Question: For Program 2A (Does not have to be demoed) You need to polish your program 1 to be able to manage the following requirements: Server:
For Program 2A (Does not have to be demoed)
You need to polish your program 1 to be able to manage the following requirements:
Server:
Should be able to handle N clients simultaneously/concurrently (i.e., should be able to connect to multiple clients and receive request from different clients and respond to each client in turn). For this you need to keep a table where each entry will keep the client number and the file descriptor for the client specific fifo for that client, so that when a request comes from client X, the table is searched for the entry containing client number X and the corresponding fd is used to respond to client X. Your server should be able to handle at least 3 clients, but the limit should really be the size of the table you create for the Client #-File Descriptor couples.
The first requests from the clients should include the client number and the name of the client specific fifo for that client, this information should be used by the server to open the client specific fifo and create a new entry in the table (client #-File Descriptor).
All subsequent requests from the client should include the client number (so the server knows who to respond to) and an integer value which will be used in part B (to be released next week). You can encode both the client number and the integer value in a string, send them as integers, whichever way you want to do it is fine as long as the server can retrieve the integer value.
The server should print to the screen the content of each request (integer) also indicating which client sent it, before replying (echoing the integer value to the client).
Client:
Make sure that the client reads the client number from the user or the command line and uses that information to produce the name of the client specific fifo that will be sent to the server after the fifo is created and opened.
Below is from programming assignment 1 for your reference.
This assignment is meant to:
Introduce students to writing basic client/server programs in C using the UNIX platform
Provide an opportunity to write code that will become the base for projects similar to that of an operating systems memory manager
This assignment requires the analysis, implementation, testing and documentation of two C program that use C on the UNIX server sapphire. A server program and a client program that will be run multiple times. As described in the following figure (From Advanced Programming in the Unix Environment Book).
Server program:
The server program will provide an echo service to the clients, i.e., whatever data the client sends to the server through the well-known FIFO, it will be returned to the sending client through that clients specific FIFO.
Server program will need to:
Create the will known FIFO where it will read its inputs from clients and open it n READ mode
Then go into a loop to read requests from clients, requests from clients will be of two types:
Requests from new clients asking to connect to the server, this requests should include the client number and the name of that client-specific FIFO. Server should open that FIFO in WRITE mode, save the file descriptor for that FIFO, associate it with that client number and return to the top of the loop
Request from the clients asking for echo service. This request should include the client number and some data (your choide-string, number, etc). The server should identify the client number and return the data to the corresponding client using that clients specific FIFO and return to the top of the loop.
When the read request from the well-known FIFO returns 0 (which means all the clients have terminated and are no longer connected to the well-known FIFO), the server should close all the FIFOS and exit.
Client Program:
The client program will connect to the server through the well known FIFO and send requests through it to the server, more specifically, the client program should:
Acquire from the user (through the command line or reading from the keyboard) what the client number this instance of the program will be (i.e., client 1, client 2, etc.)
Create the client-specific FIFO using an appropriate name (i.e., ClientNfifo, where N is the client number).
Send to the server the first request (writing to the well-known FIFO) including the client number and the name of the client-specific FIFO so the server can open it)
Open the client-specific FIFO in READ mode to be able to read replies from the server.
Go into a loop where the client will ask the user what to do next providing two choices:
1 Send request to server, in this case it will ask the user for data to send, read it from the keyboard and send the client number and data to the server, then read the reply from the server in the client-specific FIFO and write it to the screen (i.e., Reply from server: XXXXXXX where XXXXXXX is the data received from the server.
2 Quit, in this case the client should close both FIFOs and exit
Create a zip file with both your programs source file(s) and upload to blackboard please.
Make incremental progress as you develop your code and back up your files often!!
Come by during office hours after the program is finished (or set up an appointment at another convenient time) to do a demo of your client/server setup.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
