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:
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: ./major2climat0299@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...