This assignment should help you become familiar with the client-server model and interprocess communication using sockets.
This assignment requires you to write the code for 3 processes: a server (server.c), and two clients (client1.c, client2.c).
The server should create a socket and output the port number to the screen. Upon accepting a request for a connection, the server should fork a child process to deal with the request. The child should exist until the client terminates.
The child process(es) should receive a message with 3 integer fields. The child should add the values in the first 2 fields and return the result in the third field. It should output to the screen the request and results.
The server should not exit. When finished, kill the server with ctrl-C.
The clients will be virtually identical, except that one will add the numbers from 1 to 1000 and the other from 1000 down to 1. The request is a structure consisting of 3 fields: the integers to be added and the result returned from the server. Each child should print to the screen the numbers added and the result returned.
gcc -o output_file code.c -lsocket -lnsl
Open 3 windows (a combination of borg and torch). Start the server and get the port number. In each of the other 2 windows, type the command, but don't hit enter. The goal is to have both clients accessing the server concurrently. If the system is running so quickly that you can't achieve concurrency with 1000 numbers, increase the numbers and verify that your server can handle concurrent clients - the marker will be verifying this After having typed both commands, quickly start both clients by hitting the enter key in the appropriate window.
Command to run the clients should work as follows:
client# server_host port# (where server_host is either borg or torch depending on where your server is running and the port# is the port specified at runtime by the server).
Place all source code, the makefile, and readme file in a directory called assign4 and submit the directory. Also hand in a hard copy of all files at the beginning of class. Make sure that your name and student number are on the top of each file.
Sample makefile:
all : client1 client2 server
client1 : client1.c assign3.h
gcc -o client1 client1.c -lsocket -lnsl
client2 : client2.c assign3.h
gcc -o client2 client2.c -lsocket -lnsl
server : server.c assign3.h
gcc -o server server.c -lsocket -lnsl
Some tutorials and sample code for working with sockets is available on the course website. Please limit your use of "borrowed code" to these examples and credit appropriately.
50% functionality (25% server, 25% client)
50% readability (includes proper use of header files, commenting at all levels including a readme file, variable names, constants, demonstrated knowledge of how/why program is working, indentation, etc.)
Ensure that your code compiles on torch with your makefile. Provide an all: in the makefile to simplify things for the marker.