SlideShare a Scribd company logo
Choose one of these three options: A. IPC using FIFO B. Shared memory C. Sockets and Client-
Server In this lab, you will be required to write two C routines which talk to each other through a
communications channel. You can Choose to either implement the code using FIFOs, a shared
memory segment or through the use of sockets. In the description below these will be referred to
generically as "the communications channel" or just "the channel". The objective is to create a
client-server environment to copy the contents of a file from the client to the server. This will mimic
a file UPLOAD process. Your client code will run as a single process on the computer. Your server
code must also be run as a separate process on the same computer. This means having two
terminal windows running. One for the server, one for the client. No fork() or exec() calls are to be
used for this lab. The filename should be supplied to the client as a command line parameter. Your
client code, once connected, should send a message to the server. The message should contain a
filename. The server should then receive the filename and prepare to receive data. The client
should open the file and copy it through the channel to the server. You must only use read() and
write() to transfer data through the socket. Each "packet" of information sent must use a structure
that contains both the number of bytes being transferred as well as the data stream. Something
akin to: struct student_record { int nbytes; char payload[1024]; }; The server code should then
accept the data buffer through the channel and writes the identified number of bytes to the local
filename. The data exchange should happen in fixed block sizes, say 1024 bytes. When the client
sends a packet to the server containing fewer than the expected packet size, your code can
assume the client has hit the end of file. You should expect the test files I will use will be of
arbitrary length. Some will be smaller, some much larger than 1024 bytes. Restrictions: When you
are retrieving data from the source file, you must use open() and read(). You are not allowed to
use fopen() as it will not read binary files properly. You are not allowed to use the sendfile()
system call or any other bulk transfer utilities. Depending on the approach you have chosen, you
are required to read()/write() or send()/recv() the data and then push it through the channel you
created. Both the server and client should close their copy of the file. The client should then send
a disconnect message to the server and exit. Your destination filename should be something like:
lab6_sourcefile_local_clone.
A) IPC using FIFO Your client code should use two FIFOs. One for client-to-server transfers and
one for server-to-client messages. You are allowed to assume that these FIFOs have static well
known names and that only one client will ever be talking to the server at a time. The client must
check for the presence of both FIFOs before it accepts user input. You can use the access()
function from unistd.h to check for the presence of the FIFOs. If either of the FIFOs is missing, a
message should be displayed as to which is missing, then the client should exit. You can't run a
client if the FIFOs don't exist to act as communication channels to the server. Your testing logs
should show both scenarios. Your server code, which you should run first, should check for the
existence of the two FIFOs. If any of them is missing, the server code should create them. The
server code should then wait for a message to arrive from the client. It should contain the filename
being uploaded. The server must rename the file if it is going to place it in the same directory as
the source. The server should then read "structure" size chunks from the client->server FIFO and
write the appropriate data to the output file. When the number of bytes in the payload portion of
the structure is less than the buffer size, you can assume that's the last block of the file. The
server should send an "All DONE" message to the client. The client should wait to receive this
message, print out an OK message then exit. The server should remain running waiting for a
different client to connect. Ensure that once you are done running your code that you kill the
server process. Either stop it using the kill command line verb (if you created a background
process using &) or by pressing CTRL-C in the terminal window it is running under. The server
should remain running just in case a different client connects at a later time (in a real world
scenario). You could, should you want to be fancy, create a signal handler to help terminate the
server process.
B) Internet Sockets This lab is essentially a socket implementation of the FIFO process described
above. In this lab, you will be required to write two C routines which talk to each other through
proper TCP/IP sockets. The objective is to create a real client-server environment to upload the
contents of a file from the client to the server. Your client code will run as a single process on the
computer. You server code must be run as a separate process on the same computer. Note: The
fact that the client and server processes are running on the same computer is a limitation of our
lab environment. Your code should be able to run on two separate systems. Because of the
firewall protecting Loki, you cannot run the server on Loki and your client on your laptop. The
socket port will be blocked. Your client code should check for the presence of the server and your
code's ability to connect. If the client cannot connect, it should exit gracefully. Your server code
should create and listen on a proper TCP/IP socket. The server code should then wait for a
message to arrive from the client. The first message will be the name of the file being uploaded.
Next, the server should expect "structure" size chunks of data through the socket and write the
payloads to a local copy of the file. Once the file is transferred, your server code should send an
OK message to the client, then, gracefully hang up the connection. The server should remain
running waiting for a different client to connect. You need not code your server to allow for multiple
simultaneous connections (that would/should require a fork() or threads). Ensure that one you are
done running your code that you kill the server process. Either stop it using the kill command line
verb (if you created a background process using &) or by pressing CTRL-C in the terminal window
it is running under (or a signal). NOTE: On the server side, you will need to supply a PORT
number for your server to listen on. Please use the last 4 digits of your student number and add
50000 to it. So if your student number ends in 1701, code your server (and hence the client) to use
port 51701. Or if it is 17, your port number would be 50017. That way we don't interfere with each
other and we don't use a port already allocated on the system (your server won't start as the O/S
won't let it).
C) Shared memory segment. Since a shared memory segment is...shared, there is only a
requirement for one such channel for your code. This is a slightly more complex piece of code
since it will require synchronization between the two parties sharing the memory region. The
server process should start up and create the shared memory region. The client should then
connect to the shared memory region and pass the filename through it. The server should read the
filename and respond telling the client it can start transferring data. This would probably involve
some chunk of memory used to exchange "status". Since access to the shared area is
uncontrolled, you'll need to create your own handshaking routine to manage the flow control.
Maybe reserve the first few bytes of the shared region as a set of "traffic lights". As an example,
your structure might contain an extra flag field called something like: "flow". When that field is a
ZERO, the client has permission to update the data block in the shared area. Once the file chunk
has been written memory, the client changes the flag value in the "flow" (Say to a 1). The server
polls the "flow" variable (memory area) waiting for it to change to a 1. The "1" would indicate that it
is the server's turn to write the data block to disk, then set the flag to a zero. And so on until all of
the file has been transferred. You could also use a simple counter for the number of payloads
transferred. When the number changes, it means the server has written the payload to disk. Again,
not a trivial exercise but a rewarding one. Again, the shared memory region should reserve room
for both the number of bytes transferred and the data buffer. Remember that if you don't keep
track of how much data is in the region, and you don't zero it out, then you may wind up with more
data in the uploaded file than you would want. Hence, the number of bytes field in the structure to
limit what you read and write. Of course, this implementation would cause a CPU SPIN situation
waiting for the flag to change. This could be alleviated with a sleep(1) or a pause() and a alarm(1)
type signal inside each routine. I'm OK if it is a bit slow. It will help you "watch" the program work
and see any debug statements you might have in your code as you test it.

More Related Content

PDF
In C programming please CSCI 4534 Operating Systems Program.pdf
PDF
Functionality You are to create an enhanced chat system- In particular.pdf
PPT
15237197jvkhcjkgckghckghxckgjckufliufi.ppt
PDF
CODE FOR echo_client.c A simple echo client using TCP #inc.pdf
PDF
CC++ echo serverThis assignment is designed to introduce network .pdf
PPTX
communication Mechanism in Client Server Model
PDF
Networking lab
In C programming please CSCI 4534 Operating Systems Program.pdf
Functionality You are to create an enhanced chat system- In particular.pdf
15237197jvkhcjkgckghckghxckgjckufliufi.ppt
CODE FOR echo_client.c A simple echo client using TCP #inc.pdf
CC++ echo serverThis assignment is designed to introduce network .pdf
communication Mechanism in Client Server Model
Networking lab

Similar to Choose one of these three options A IPC using FIFO B Shar.pdf (20)

PPT
Socket programming
PPT
Socket Programming Tutorial 1227317798640739 8
PPT
Socket Programming Tutorial
PPT
Socket Programming
PPT
Socket programming-tutorial-sk
DOCX
Please look at the attach See.doc. I am getting this error all th.docx
PPTX
Byte Ordering - Unit 2.pptx
PDF
Hello,Ther is some problem in you codeI made my own programme as.pdf
PPTX
Socket Programming
PPT
Sockets
PPTX
BUFFERS, PIPE, DEVICE AND PROGRAM MANAGEMENT.pptx
PPTX
Networking in Python2025 (programs allll)
PDF
Select and poll functions
PPTX
Network Programming-Python-13-8-2023.pptx
PPT
03-socketprogramming for college students.ppt
PPT
03-socketprogrsamming forcoleeger students.ppt
PPTX
Socket programming
PDF
How do event loops work in Python?
PPT
Lecture03-IPC.ppt
PPT
Socket programming
Socket Programming Tutorial 1227317798640739 8
Socket Programming Tutorial
Socket Programming
Socket programming-tutorial-sk
Please look at the attach See.doc. I am getting this error all th.docx
Byte Ordering - Unit 2.pptx
Hello,Ther is some problem in you codeI made my own programme as.pdf
Socket Programming
Sockets
BUFFERS, PIPE, DEVICE AND PROGRAM MANAGEMENT.pptx
Networking in Python2025 (programs allll)
Select and poll functions
Network Programming-Python-13-8-2023.pptx
03-socketprogramming for college students.ppt
03-socketprogrsamming forcoleeger students.ppt
Socket programming
How do event loops work in Python?
Lecture03-IPC.ppt
Ad

More from aghsports (20)

PDF
Clck the kon to view tre table A 147425 a H 425 H2lt4.pdf
PDF
Classify the following data Indicate whether the data is qu.pdf
PDF
Class Activity Perform a group of 3 member Choose any of th.pdf
PDF
Class Buttercup public Buttercupint baddifs num_punc.pdf
PDF
class People protected string name int age public XXX .pdf
PDF
Clasifique cada ejemplo o definicin segn se aplique al gen.pdf
PDF
Circuit diagram Please build the following circuit and test.pdf
PDF
Choose the incorrect statement below A X is an estimator .pdf
PDF
Cisconun Tedarik Zinciri Cisconun tedarik zinciri d kayna.pdf
PDF
CISC 341 Computer Architecture You must show your work to.pdf
PDF
Cinematix se vuelve mvil Cinematix Cinema ha revisado reci.pdf
PDF
CIGS thinfilm solar modules are potentially competitive wit.pdf
PDF
Choose the correct statement below A Estimators do not gen.pdf
PDF
Choose the correct word to complete these descriptions of st.pdf
PDF
CHOOSE ONLY ONE OF THE FOLLOWING 7 marks 1 Describe in .pdf
PDF
Choose the correct answer 1 The method _ is called by the .pdf
PDF
Choose your own project idea or select one of the following.pdf
PDF
choose the correct answer 1 Water will flow into the beaker.pdf
PDF
Choose the best description of a cDNA library a mixture o.pdf
PDF
Choose an indicator from The Canadian Environmental Sustaina.pdf
Clck the kon to view tre table A 147425 a H 425 H2lt4.pdf
Classify the following data Indicate whether the data is qu.pdf
Class Activity Perform a group of 3 member Choose any of th.pdf
Class Buttercup public Buttercupint baddifs num_punc.pdf
class People protected string name int age public XXX .pdf
Clasifique cada ejemplo o definicin segn se aplique al gen.pdf
Circuit diagram Please build the following circuit and test.pdf
Choose the incorrect statement below A X is an estimator .pdf
Cisconun Tedarik Zinciri Cisconun tedarik zinciri d kayna.pdf
CISC 341 Computer Architecture You must show your work to.pdf
Cinematix se vuelve mvil Cinematix Cinema ha revisado reci.pdf
CIGS thinfilm solar modules are potentially competitive wit.pdf
Choose the correct statement below A Estimators do not gen.pdf
Choose the correct word to complete these descriptions of st.pdf
CHOOSE ONLY ONE OF THE FOLLOWING 7 marks 1 Describe in .pdf
Choose the correct answer 1 The method _ is called by the .pdf
Choose your own project idea or select one of the following.pdf
choose the correct answer 1 Water will flow into the beaker.pdf
Choose the best description of a cDNA library a mixture o.pdf
Choose an indicator from The Canadian Environmental Sustaina.pdf
Ad

Recently uploaded (20)

PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Institutional Correction lecture only . . .
PDF
01-Introduction-to-Information-Management.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Classroom Observation Tools for Teachers
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Final Presentation General Medicine 03-08-2024.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Institutional Correction lecture only . . .
01-Introduction-to-Information-Management.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Classroom Observation Tools for Teachers
Module 4: Burden of Disease Tutorial Slides S2 2025
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
O7-L3 Supply Chain Operations - ICLT Program
Renaissance Architecture: A Journey from Faith to Humanism
PPH.pptx obstetrics and gynecology in nursing
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
RMMM.pdf make it easy to upload and study
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx

Choose one of these three options A IPC using FIFO B Shar.pdf

  • 1. Choose one of these three options: A. IPC using FIFO B. Shared memory C. Sockets and Client- Server In this lab, you will be required to write two C routines which talk to each other through a communications channel. You can Choose to either implement the code using FIFOs, a shared memory segment or through the use of sockets. In the description below these will be referred to generically as "the communications channel" or just "the channel". The objective is to create a client-server environment to copy the contents of a file from the client to the server. This will mimic a file UPLOAD process. Your client code will run as a single process on the computer. Your server code must also be run as a separate process on the same computer. This means having two terminal windows running. One for the server, one for the client. No fork() or exec() calls are to be used for this lab. The filename should be supplied to the client as a command line parameter. Your client code, once connected, should send a message to the server. The message should contain a filename. The server should then receive the filename and prepare to receive data. The client should open the file and copy it through the channel to the server. You must only use read() and write() to transfer data through the socket. Each "packet" of information sent must use a structure that contains both the number of bytes being transferred as well as the data stream. Something akin to: struct student_record { int nbytes; char payload[1024]; }; The server code should then accept the data buffer through the channel and writes the identified number of bytes to the local filename. The data exchange should happen in fixed block sizes, say 1024 bytes. When the client sends a packet to the server containing fewer than the expected packet size, your code can assume the client has hit the end of file. You should expect the test files I will use will be of arbitrary length. Some will be smaller, some much larger than 1024 bytes. Restrictions: When you are retrieving data from the source file, you must use open() and read(). You are not allowed to use fopen() as it will not read binary files properly. You are not allowed to use the sendfile() system call or any other bulk transfer utilities. Depending on the approach you have chosen, you are required to read()/write() or send()/recv() the data and then push it through the channel you created. Both the server and client should close their copy of the file. The client should then send a disconnect message to the server and exit. Your destination filename should be something like: lab6_sourcefile_local_clone. A) IPC using FIFO Your client code should use two FIFOs. One for client-to-server transfers and one for server-to-client messages. You are allowed to assume that these FIFOs have static well known names and that only one client will ever be talking to the server at a time. The client must check for the presence of both FIFOs before it accepts user input. You can use the access() function from unistd.h to check for the presence of the FIFOs. If either of the FIFOs is missing, a message should be displayed as to which is missing, then the client should exit. You can't run a client if the FIFOs don't exist to act as communication channels to the server. Your testing logs should show both scenarios. Your server code, which you should run first, should check for the existence of the two FIFOs. If any of them is missing, the server code should create them. The server code should then wait for a message to arrive from the client. It should contain the filename being uploaded. The server must rename the file if it is going to place it in the same directory as the source. The server should then read "structure" size chunks from the client->server FIFO and write the appropriate data to the output file. When the number of bytes in the payload portion of the structure is less than the buffer size, you can assume that's the last block of the file. The
  • 2. server should send an "All DONE" message to the client. The client should wait to receive this message, print out an OK message then exit. The server should remain running waiting for a different client to connect. Ensure that once you are done running your code that you kill the server process. Either stop it using the kill command line verb (if you created a background process using &) or by pressing CTRL-C in the terminal window it is running under. The server should remain running just in case a different client connects at a later time (in a real world scenario). You could, should you want to be fancy, create a signal handler to help terminate the server process. B) Internet Sockets This lab is essentially a socket implementation of the FIFO process described above. In this lab, you will be required to write two C routines which talk to each other through proper TCP/IP sockets. The objective is to create a real client-server environment to upload the contents of a file from the client to the server. Your client code will run as a single process on the computer. You server code must be run as a separate process on the same computer. Note: The fact that the client and server processes are running on the same computer is a limitation of our lab environment. Your code should be able to run on two separate systems. Because of the firewall protecting Loki, you cannot run the server on Loki and your client on your laptop. The socket port will be blocked. Your client code should check for the presence of the server and your code's ability to connect. If the client cannot connect, it should exit gracefully. Your server code should create and listen on a proper TCP/IP socket. The server code should then wait for a message to arrive from the client. The first message will be the name of the file being uploaded. Next, the server should expect "structure" size chunks of data through the socket and write the payloads to a local copy of the file. Once the file is transferred, your server code should send an OK message to the client, then, gracefully hang up the connection. The server should remain running waiting for a different client to connect. You need not code your server to allow for multiple simultaneous connections (that would/should require a fork() or threads). Ensure that one you are done running your code that you kill the server process. Either stop it using the kill command line verb (if you created a background process using &) or by pressing CTRL-C in the terminal window it is running under (or a signal). NOTE: On the server side, you will need to supply a PORT number for your server to listen on. Please use the last 4 digits of your student number and add 50000 to it. So if your student number ends in 1701, code your server (and hence the client) to use port 51701. Or if it is 17, your port number would be 50017. That way we don't interfere with each other and we don't use a port already allocated on the system (your server won't start as the O/S won't let it). C) Shared memory segment. Since a shared memory segment is...shared, there is only a requirement for one such channel for your code. This is a slightly more complex piece of code since it will require synchronization between the two parties sharing the memory region. The server process should start up and create the shared memory region. The client should then connect to the shared memory region and pass the filename through it. The server should read the filename and respond telling the client it can start transferring data. This would probably involve some chunk of memory used to exchange "status". Since access to the shared area is uncontrolled, you'll need to create your own handshaking routine to manage the flow control. Maybe reserve the first few bytes of the shared region as a set of "traffic lights". As an example,
  • 3. your structure might contain an extra flag field called something like: "flow". When that field is a ZERO, the client has permission to update the data block in the shared area. Once the file chunk has been written memory, the client changes the flag value in the "flow" (Say to a 1). The server polls the "flow" variable (memory area) waiting for it to change to a 1. The "1" would indicate that it is the server's turn to write the data block to disk, then set the flag to a zero. And so on until all of the file has been transferred. You could also use a simple counter for the number of payloads transferred. When the number changes, it means the server has written the payload to disk. Again, not a trivial exercise but a rewarding one. Again, the shared memory region should reserve room for both the number of bytes transferred and the data buffer. Remember that if you don't keep track of how much data is in the region, and you don't zero it out, then you may wind up with more data in the uploaded file than you would want. Hence, the number of bytes field in the structure to limit what you read and write. Of course, this implementation would cause a CPU SPIN situation waiting for the flag to change. This could be alleviated with a sleep(1) or a pause() and a alarm(1) type signal inside each routine. I'm OK if it is a bit slow. It will help you "watch" the program work and see any debug statements you might have in your code as you test it.