Building the Client and Server Programs For this assignment, download three files from WorldClass: the source code file for the client, client.c, the source code file for the server, server.c, and a Makefile for both. With all three files in the same directory, to build the executable files simply type at the command prompt: make Using rules specified in the Makefile, the make command will invoke the gce compiler, which will compile and link both the client and server programs. Then whenever you modify either source file, simply type make again, and it will rebuild any program whose source file has changed. If a program's source file has not been modified, make will not rebuild it. To clean up, i.e., delete the executable programs and the object files, type: make clean 3 Running the Programs When running the programs, it is probably easiest to open two terminal windows, one for the client and the other for the server. At one of the terminal windows, run the server program by typing: ./server This will start the server, which listens for incoming TCP connections on a default port. To specify a different port, invoke the server as: ./server Note that port numbers up to 1024 are referred to as well-known ports, and are therefore reserved for specific applications such as HTTP, FTP, IMAP mail, etc. They should not be used for your program. Instead, use a port number greater than 1024, which is far less likely to conflict with any existing protocol. In the other terminal window, invoke the client as such: ./client localhost Because we are running both client and server on the same machine, we specify the server name as "localhost". In this example we are also using the default port. However, we don't need to do that. If running the server on a different machine, let's say a machine named host1, specify that hostname instead: ./client host1 Note that in these example it's listening on the default port if running the server on a different machine and a port other than the default port (for this example let's assume the server is listening on port 4435), specify such after the host machine name separated by a colon: ./client host1:4435 Upon successfully completing a TCP handshake with the server, the client application will prompt you to enter a text string message. Once entered, the client strips the trailing newline character from your message and writes the message to a socket descriptor. This transmits the message to the server, which is listening on its own socket for that connection. The server reads your message from the socket and outputs it to the terminal. After receiving the message, the server closes the connection with the client but continues to listen for new incoming connections. 4 Requirements Your job is to modify both the client and server applications as such: Server. The server should function as an echo server, which means it simply returns to the client exactly the message it receives from the client. In the server code, a call to read() on the socket descriptor copies the received message into a buffer. This modification requires that message be transmitted back to the client with a call to write() on the same socket descriptor. In the server code, include a printf() statement to standard output indicating the message is being transmitted to the client. Client. After transmitting the message to the server, the client process should then await the reply. To do this, in the client code add a call to read() on the same socket descriptor used to send the message. By default, read() is a blocking system call, so the client process will wait for a response from the server before it continues execution. Once the reply is received, output a statement to standard output indicating the message was received (and be sure include the message in the output). 5 Requirements Correctness of your program requires the following conditions be satisfied: • You may build and test your program on any POSIX-compliant platform, e.g., Linux, Mac OS X, Solaris, etc. Please let me know what platform you built and tested your code on when you submit. • Appropriate output statements should be included in your code so it is easy for me to see that your program works correctly. The message should be exactly what is transmitted; garbled messages will result in point deduction according to the grading rubric. • Be sure to put your name in the header block of comments for both client and server code modules. 6 Deliverables Turn in the C code for your programs, i.e., client.c and server.c, through the World Class dropbox for Programming Assignment #2 no later than 11:59 p.m. on the posted due date.