Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Client /Server Objective: Create programs that are run independently and can use simple IPC using FIFOs/named pipes to pass information back and forth in a

Client /Server

Objective: Create programs that are run independently and can use simple IPC using FIFOs/named pipes to pass information back and forth in a client/server fashion. The information/request from the client will look like system calls and will include information for the server to be able to identify which client requested it and what request it is and its associated parameters. This assignment requires the analysis, implementation, testing and documentation of two C program that use C on the Linux server sapphire or your own Linux box or virtual machine. A server program and a client program that will be run concurrently. Server program: The server program will provide a simple echo service to clients that connect with it and send requests. Server program will be an iterative server which can receive requests from multiple clients, although it process the requests in a serial fashion, one at a time, i.e., request from client one, request from client three, request from client two etc. So, Server will need to create a well-known FIFOs where it will read its inputs from the clients and open it in READ mode (will block of course until a client opens the fifo in write mode). After the first client connects, the server should also open the well known fifo in write mode, to prevent the server from quitting when there are no clients connected. Server will then go into a loop to read from the pipe to receive requests from clients that will consist of the following types of request: a) Requests from a new clients asking to connect to the server, this requests should include the client ID/number and the name of that client-specific FIFO (used by the client to receive replies from the server). Server should open that FIFO in WRITE mode, save the file descriptor and the client ID/number into a CONNECTED CLIENTS table for use when replies need to be sent to THAT client. b) System call-like Request from a connected client, including parameters. In this case, the server should display in the screen which client sent the request, what the request number/sys call number is and its associated parameters. It should then send the requests and its parameters back to THE CLIENT it got it from (after looking up the client ID/number and retrieving the file descriptor for the pipe associated with THAT client) See the type of system call-like request in the description of the client program. c) Client request to disconnect from the server. In this case, the server should reply with an OK message to that client and then close THAT clients fifo and remove the clients entry from the CONNECTED CLIENTS table. d) There should be a special request-STOP that can be sent by a client to indicate to the server that it should close all fifos and terminate (this is not normally part of a standard server code which should run indefinitely, but will give you a way to gracefully shutdown the server. This should ONLY be processed if the client requesting it is the last connected client. After each of these four types of requests, the server should print to the screen enough information to show which client is requesting and what the request was (client ID/number, type of requests, and associates parameters if any). It should also print the reply being sent. 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.) Open the well-known servers fifo in write mode to communicate with the server (which will unblock the server from its fifo open call) Create the client-specific FIFO using an appropriate name (e.g., ClientNfifo, where N is the client number) and send the initial connect request to the server including Client number AND name of the client-specific FIFO. Open the client-specific FIFO in READ mode to be able to read replies from the server. This will block the client until the server opens the fifo in write mode. After this, the client should go into a loop where the client will ask the user what to do next? providing three choices: o 1 Send request to server, in this case it will ask the user for data: System call number? Parameters? (see description below) read the data from the keyboard and appropriately format an system call-like request and send to the server, then read the reply from the server in the client-specific FIFO and write it to the screen. o 2 EXIT - indicates THIS client does not want to issue more requests to the server, it should close its pipes and exit. o 3 STOP - indicates THIS client does not want to issue more requests to the server, and it should also send a STOP request to the server (so that it can gracefully terminate) before closing its pipes and exiting. No more clients can connect to the server after this. The first step in writing a client/server application is define the communications protocol between both applications. In other words, how are you going to encode the requests and reply into a message, you can encode data in string forms, you can use integer data, separating each piece with a , - a space, a new line character, or any other kind of separator. PART 1 includes a set of flowcharts for both client and server, as well as a description of the messages that will be sent back and forth between the client and the server and how the data in each message will be encoded. THIS IS DUE MONDAY March 4th. 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!! Logical Description of system call-like requests and their associated parameters: SYS CALL NUMBER SYS CALL NAME PARAMETERS AND TYPE 1 FORK None 2 SLEEP Int number_nanoseconds 3 OPEN String file name Int flags/access mode Your PART 1 assignment should indicate how the information in each row from the table above will be encoded in a message that the client will send to the server and how the reply for each will look like. EXTRA CREDIT: (20 Points) If you implement your server using multiple threads so that each client requests are handled by a separate thread. In this case, the four request should be handled by the server as follows: a) HANDLED BY MAIN THREAD - Requests from a new clients asking to connect to the server, this requests should include the client ID/number and the name of that client-specific FIFO (used by the client to receive replies from the server). Server should open that FIFO in WRITE mode, save the file descriptor and the client ID/number into a CONNECTED CLIENTS table for use when replies need to be sent to THAT client. Also create a new thread which will read and process requests from THIS client. Requests of type b), c) and d) should be handled by the child thread associated with each client. b) System call-like Request from a connected client, including parameters. In this case, the server should display in the screen which client sent the request, what the request number/sys call number is and its associated parameters. It should then send the requests and its parameters back to THE CLIENT it got it from (after looking up the client ID/number and retrieving the file descriptor for the pipe associated with THAT client) See the type of system call-like request in the description of the client program. c) Client request to disconnect from the server. In this case, the server should reply with an OK message to that client and then close THAT clients fifo and remove the clients entry from the CONNECTED CLIENTS table. d) There should be a special request-STOP that can be sent by a client to indicate to the server that it should close all fifos and terminate (this is not normally part of a standard server code which should run indefinitely, but will give you a way to gracefully shutdown the server. This should ONLY be processed if the client requesting it is the last connected client.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions