PROGRAM DESCRIPTION:

In this assignment, you will write a complete C program to support a client/ server and pseudo-client/client model) using Linux sockets and run on standard Linux CSE machines (i.e., cse01 cse06). The CSE machines are just a generic set of computers that can be remotely accessed using putty. They run the C90 version of the C programming language. The program will consist of a server that will keep a running sum of the integral data being sent by two clients as follows:

Server

  • The server will receive integer values from up to two clients (in any order) and add these values to its current total separate for each client, which the server then returns back to the originating client so that the client is aware of its most up-to- date total. The server can have, at most, 2 clients connected at one time, though this functionality (i.e., a client being able to send an integral value to the server and the server responding to this request) should still continue even when only 1 client is connected.
  • When the total sum for an individual client reaches a value between 1,024 and 49,151 (the range of ports registered for general use), the server will return this value back to the client as usual, but the server will also send the message PORT followed by this value to the other client, which will act as a trigger for both clients that the client whose value exceeded the port threshold will then act as a server for the other client to connect to (see Clients section below for details). Upon reaching this threshold value, the server shall reset the individual clients current total back to 0, even If only 1 client is connected at the time.
  • The server will provide important status updates of messages sent and received, such as connection events, each clients running total, and when the port threshold has been reached.
  • The server will continue to listen for clients and run indefinitely until manually terminated (using, for example, Ctrl-C). A client may disconnect and later re- connect to the server. Up to 2 clients may connect and disconnect at any time, but the server should still be able to respond to connected clients while listening for new clients (if 1 or no clients are connected). If 2 clients are already connected and another client attempts to connect, the server shall reject the connection (accepting the connection, realizing there are too many clients, then disconnecting is acceptable), but keep the other 2 connections active.

Clients (note that there are up to 2 clients)

  • Once connected to the server, a user will manually enter integral values using the keyboard for each client that will be sent to the server. The server, in response to this integral value, will send the client a current individual total for that client so that the client is aware of the most up-to-date total.
  • Once the current individual total for a client reaches a value between 1,024 and 49,151 (the range of ports registered for general use), the originating client whose total has reached this threshold will then itself start acting as the server for the remote client to connect to, using this total as the port number. The remote client will then (1) disconnect from the server, (2) connect to the originating client (i.e., the new client server), (3) send its current total to the originating, and (4) disconnect from the originating client. The remaining active client should still be connected to the server and may continue sending its own integer values to the server.
  • If more than 2 clients attempt to connect to the server, the server shall reject the connection of the third client, which will then disconnect (if it did manage to connect) and then terminate the program. The other previously connected 2 clients shall remain active.
  • Each client will provide important status updates of messages sent and received, such as connection events, the clients running total and when a client-client connection is being established.
  • A client may voluntarily quit sending integer values to the server when the user manually enters a 0 for its integer value (whereupon the client will disconnect from the server).

Your programs (a server program and a client 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. The server will accept the port number to communicate on as an argument to the server program, while the client (again, two clients using the same code) will accept the three arguments the server hostname and port number and the remote clients IP address to communicate on as arguments to the client program. Your code will handle errors appropriately, such as printing an error message, disconnecting the client, or termination of the program.

The server and client code may be executed as follows:

SERVER: (on cse06)
./major2svr < svr_port >
For example, ./major2svr 8001.

CLIENT 1: (on cse04, or 129.120.151.97)
./major2cli < svr_host > < svr_port > < rem_ipaddr >
For example, ./major2cli cse06 8001 129.120.151.98.

CLIENT 2: (on cse05, or 129.120.151.98)
./major2cli < svr_host > < svr_port > < rem_ipaddr >
For example, ./major2cli cse06 8001 129.120.151.97.

SAMPLE OUTPUT (user input shown in bold):

==> SERVER on cse06
mat0299@cse06:~/csce3600/fa18/major2$ ./major2svr
usage: ./major2svr
mat0299@cse06:~/csce3600/fa18/major2$ ./major2svr
8001 Waiting for Incoming Connections...
Client Connection Accepted
Client Handler Assigned
Client Connection Accepted
Client Handler Assigned
Client 2 Disconnected, Reset Total
Client Connection Accepted
Client Handler Assigned
CLIENT 1: 100 - Total: 100
CLIENT 2: 35 - Total: 35
CLIENT 2: 48 - Total: 83
CLIENT 1: 500 - Total: 600
CLIENT 2: 159 - Total: 242
CLIENT 1: 400 - Total: 1000
CLIENT 2: 73 - Total: 315
CLIENT 1: 100 - Total: 1100
Sending Client 1 Port 1100 to Client 2, Reset
Total Client 2 Disconnected, Reset Total CLIENT 1:
200 - Total: 200
Client Connection Accepted
Client Handler Assigned
CLIENT 2: 26 - Total: 26
CLIENT 2: 4000 - Total: 4026
Sending Client 2 Port 4026 to Client 1, Reset
Total Client 1 Disconnected, Reset Total
Client 2 Disconnected, Reset Total
^C
==> CLIENT on cse04 (first client to connect to server)
mat0299@cse04:~/csce3600/fa18/major2$ ./major2cli usage: ./major2cli
mat0299@cse04:~/csce3600/fa18/major2$
./major2cli cse06 8001 129.120.151.98 Connected
Enter CLIENT 1 Data: 100
SERVER Total: 100
Enter CLIENT 1 Data: 500
SERVER Total: 600
Enter CLIENT 1 Data: 400
SERVER Total: 1000
Enter CLIENT 1 Data: 100
SERVER Total: 1100
Enter CLIENT 1 Data: Connection Accepted
Handler Assigned
Received 315 from Remote Client
Remote Client Disconnected
200
SERVER Total: 200
Enter CLIENT 1 Data: SERVER Message: PORT 4026
CLIENT 1 Disconnecting from SERVER...
Sending 1300 to Remote Client
CLIENT 1 Disconnecting from CLIENT 2...
==> CLIENT on cse05 (second client to connect to server)
mat0299@cse05:~/csce3600/fa18/major2$ ./major2cli cse06 8001
129.120.151.97 Connected
Enter CLIENT 2 Data: 0
CLIENT 2 Disconnecting from SERVER...
mat0299@cse05:~/csce3600/fa18/major2$ ./major2cli cse06 8001
129.120.151.97 Connected
Enter CLIENT 2 Data: 35
SERVER Total: 35
Enter CLIENT 2 Data: 48
SERVER Total: 83
Enter CLIENT 2 Data: 159
SERVER Total: 242
Enter CLIENT 2 Data: 73
SERVER Total: 315
Enter CLIENT 2 Data: SERVER Message: PORT
1100 CLIENT 2 Disconnecting from SERVER...
Sending 315 to Remote Client
CLIENT 2 Disconnecting from CLIENT 1...
mat0299@cse05:~/csce3600/fa18/major2$ ./major2cli cse06 8001
129.120.151.97 Connected
Enter CLIENT 2 Data: 26
SERVER Total: 26
Enter CLIENT 2 Data: 4000
SERVER Total: 4026
Enter CLIENT 2 Data: Connection
Accepted Handler Assigned
Received 1300 from Remote Client
Remote Client Disconnected
0
CLIENT 2 Disconnecting from SERVER...
==> CLIENT on cse03 (this is the third client attempting to connect)
mat0299@cse03:~/csce3600/fa18/major2$ ./major2cli cse06 8001 129.120.151.97
SERVER: Too Many Clients Connected. Disconnecting...
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.