PROGRAM 9 (optional assignment): MotServer.c MotClient.c --------------------------------------------------------- This program may replace a program of a lower grade. Assigned: Thursday May 01, 2003 Deadline: Thursday May 08, 2003 at MIDNIGHT The goal of this assignment is to introduce you to sockets. In this you will use UNIX sockets to implement a "message of the day" server. In this project you will implement two programs, a client and a server program; the programs should be compiled separately, so that they each have their own executable image. The two processes will communicate with each other in a connection-oriented manner using sockets. The client/server action should proceed as follows: INTERACTION SEQUENCE: -------------------- Client: c1. Connect to the server via a TCP socket c2. Read (from the socket) and display the prompt message sent (see step s2 in server) from the server c3. Input username from the local user and send to the server c4. Read (from the socket) and display the message of the day OR an error message that is returned by the server (see step s4 in server), whichever is appropriate. c5. The client closes the connection. Server: s0. [Initialization] The server is initialized with a set of 5 valid usernames (strings) and 5 message-of-the-day messages (strings). The usernames should be read INPUT (read from stdin) and not hard coded. Allow for some length variation (up to 10 characters). s1. Wait for a client connection on a welcoming socket. s2. When a client connection is accepted on the welcoming socket, the server sends a prompt message (of your choosing) to the client asking for the client's username. s3. Read and display the username returned by the client (see step c3 in client). If the name is valid, your server should send a message-of-the-day (any of the messages initialized in step s0) message back to the client. If the name is not valid, your server should send an error message. s4. The server then closes the connection to the client and loops back waiting for another connection. REQUIREMENTS: ------------ o This program must be written in C. Your program will be graded using the compiler on AJAX with path: /opt/sfw/bin/gcc. It is important that you use the CORRECT compiler as their is no contest period for this assignment. o Check for an error return from all system calls (except exit()). o Make sure you close every socket that you use in your program. If you abort your program, the socket may still hang around and the next time you try and bind a new socket to the port ID you previously used (but never closed), you may get an error. o Your server should terminate (gracefully) upon receipt of a control-C from the keyboard or of a kill -TERM signal. You should install a signal handler to make sure that your sockets are closed before your server terminates (a call to exit will insure that these sockets are closed gracefully before the server terminates). HINTS: ----- o Note that read and write might return without having read or written the full number of bytes requested. In such a case, these calls will return a positive return value indicating the number of bytes actually read or written. If the number does not correspond with the number requested, be sure to loop back until all the data has been transferred. o If you need to know your host's IP address, you can telnet to your own machine and seeing the dotted decimal address displayed by the telnet program. You can also use the UNIX nslookup command, e.g. on ajax: 1. type nslookup at the unix/ajax prompt 2. type a "host name" 3. observe the IP number of ajax (128.192.251.3) {ajax:maria:138} nslookup Default Server: dns1.uga.edu Address: 128.192.1.9 > ajax Server: dns1.uga.edu Address: 128.192.1.9 Name: ajax.cs.uga.edu Address: 128.192.251.3 o You may test your program by be running both the client and server on the same machine (e.g., by starting up the client and running it in the background (or running them in different xterms), and then starting the server [or vice versa]). Recall the use of the ampersand to start a process in the background. o If you need to kill your server after you have started it, you can use the UNIX kill command. Use the UNIX ps command to find the process id of your server. {ajax:maria:145} kill -TERM 1508 o Also, please be aware that ports, when bound to sockets, are system-wide values and thus other people may be using the port number you are trying to use. To decrease the likelihood of conflict you should probably use use a port number in the 5000 range then append the last three digits of you social security number, e.g. if your social security number is 255 56 9688, the port number should be 5688. Otherwise several people may attempt to use the SAME port number for their server, i.e. 5000, and only one will succeed in getting the port. OTHER REQUIREMENTS: ------------------ o Properly commented code o Modularized program o Good software engineering techniques, hints in text book. o You must submit at least the following files (i.e., all the files necessary to compile your program): README.txt MotServer.c MotClient.c Makefile REPORT.txt - copy and past your sessions with your client and server. To submit the files, you will need to use the submit program. Your files need to be under a common subdirectory called "1730_program9". Execute the below command line while in your home directory: submit 1730_program9 cs1730 NOTE: you need to be LOGGED ONTO ajax when you execute the submit command. REFERENCES/RESOURCES -------------------- Networking tutorial: ------------------- Beej's Guide to Network Programming http://www.ecst.csuchico.edu/~beej/guide/net/ RPI Socket tutorial: http://www.cs.rpi.edu/courses/sysprog/sockets/sock.html Jim Frost Guide to Socket Programming: http://world.std.com/~jimf/papers/sockets/sockets.html http://world.std.com/~jimf/papers/sockets/sockets.html Jeff Donahoo's Tutorial: http://cs.ecs.baylor/~donahoo/practical/CSockets links to code (there is also a Java version) A short tutorial on socket programming, from the University of Wisconsin (from UMass) in postscript ftp://gaia.cs.umass.edu/cs653/sock.ps Bunch of links: http://www.cs.buffalo.edu/~milun/unix.programming.html MANUALS: http://www.eecs.umich.edu/~farnam/482/Winter99/482.html socket programming