Question: In this assignment, you will write two complete C programs( two source code files ) to support a client/server model using Linux sockets for a

In this assignment, you will write two complete C programs(two source code files) to support a client/server model using Linux sockets for a ticket system. Your program will develop a two-tiered ticketing system that will consist of a ticket outlet (i.e., the server) that will provide services to BUY and RETURN tickets to two local ticket distributors (i.e., the clients) as follows:

Server

o The server will generate tickets, where = 20, and each ticket will be a randomly generated (and unique) 5-digit number. In this case, the server will therefore maintain a database of 20 tickets (i.e., unique 5-digit integers).

o When asked for a ticket using the BUY request, the server will look at its database to see if any tickets are available. If there are available tickets, the server will return the unique 5-digit ticket number to the client. If no tickets remain, the server will return a FULL response and reject the request. The server must remain connected and available, however, to accept additional requests as clients may return tickets using the RETURN request so that tickets become available to BUY.

o When a client returns a ticket using the RETURN request, the server will place it back into the ticket pool, hopefully to be used later when another BUY request comes in from a client. There may be cases, however, when a client attempts to return an invalid ticket. In this case, the server should return a NOTEXIST response and reject this RETURN request.

o For any request other than BUY or RETURN, the server should return an INVALID response and reject the request.

o The server should provide an initial and final list of tickets with their status before both clients are connected and after both clients are disconnected, respectively. Additionally, the server should print any requests it receives and the various statuses that occur during the execution of the program.

o When no clients remain connected to the server, the server will complete its operations and shut down.

Clients (note that there are 2 clients, but 1 client source code)

o The client will request a ticket from the server using the BUY request. 2

o The client may also, from time to time, return a ticket to the server using the RETURN request. The client should provide the ticket number that is being returned in this request.

o Each client will make 20 requests to the server, where approximately 75% of the requests should be to BUY a ticket and 25% of the requests should be to RETURN a ticket using a random number generator. If the client has no tickets, but chooses to RETURN a ticket, your client code should create an invalid ticket and attempt to return it to the server (the server should catch this and reject the request). When all of the client requests have been processed, the client will disconnect from the server. This process should be automated and executed within the code (not input from a user).

Your program should run on the INET domain using SOCK_STREAM (i.e., TCP) sockets so that the server and each of the two clients execute on three different CSE machines at the same time.

Given the randomness of the requests, it could be that not all of the client requests will be met, so you will need to make sure you are able to handle error cases, such as a client trying to return an invalid ticket or the server running out of tickets.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!