The goal of this assignment is to introduce you to the idea of building a client and server program and running them. It will give you a baseline to build more code upon in future projects. The programs built for this assignment will be fairly limited, future projects will require more robust and user-friendly solutions.
In all problems you should make an effort to handle errors in a reasonable way, they will be tested with invalid inputs or usage. Give the user a meaningful message if they misuse the program or an error occurs.
The sample input/output shown in the problem statements are not an exhaustive list of tests, you should invent and try others. The sample runs are what your output must look like. Sample input and output files, if available, can be found in /afs/umbc.edu/users/g/l/glong/pub/www/cmsc491n/assign
Your code should have some comments. They should indicate who wrote the program, what the purpose of the program is, how to run the program and explain what any important or potentially confusing code is doing.
Assignment Due: Wed 22 Sep
To submit: submit cs491n clisrv udp_srv.c udp_cli.c tcp_srv.c tcp_cli.c
Write a UDP Client/Server pair of programs in C, using the skeletons given in class and the text as a model. The pair will trade ASCII string messages to capitalize letters.
The server should be iterative, non-fork()ing. It will accept any incoming messages and send them back, with all lowercase letters found in the message turned into uppercase. It should print out messages received and those sent back to each client for the user.
The client should send a message to the server, a string of text. It should expect the same length string back, with letters changed. It should print out the message it is sending and the one it has received for the user, then exit.
You may find the C functions islower() and toupper() useful.
Remember how C strings work. There are n characters in the array, with one extra for the NULL string terminator. Whether you choose to send the NULL byte in the message or not makes a difference in how you deal with the string. Be sure to document your choice of how you're sending the data in comments.
Submit your pair of programs as "tcp_srv.c" and "tcp_cli.c". Just the simplest version you have working, with hard-coded values for the message and IP/port values (IP = 127.0.0.1). Be sure to test with multiple clients at the same time.
sample of server output $ udp_srv server recvs: //moose moose GOOSE!// server sends: //MOOSE MOOSE GOOSE!// server recvs: //bite my SHINY metal// server sends: //BITE MY SHINY METAL// control-c to stop sample of client output $ udp_cli client sends: //moose moose GOOSE!// client recvs: //MOOSE MOOSE GOOSE!// $ exit()s on it's own
Some suggested experiments and work to try after you get the basic version working are listed below. They are not required for this assignment, but will prepare you for the others to come.
Write a TCP Client/Server pair of programs in C, using the skeletons given in class and the text as a model. The pair will trade ASCII string messages to perform word-counting.
The server should accept connections from multiple clients, fork()ing to handle each one. It will expect the client to send it a message containing a text string. It will accept the string, count the words present in the string, and send back a string containing the total. It will then close the connection. It should print the messages received and the counts being returned. to stdout for the user.
The client should connect to the server, send a text string over, and then receive a message containing a number. It should print out the message it is sending as well as the count returned for the user, and then exit.
For purposes of this assignment, a word is any sequence of non-space characters.
If your bind() call is failing, change ports.
Remember how C strings work. There are n characters in the array, with one extra for the NULL string terminator. Whether you choose to send the NULL byte in the message or not makes a difference in how you deal with the string. Be sure to document your choice of how you're sending the data in comments.
Submit your pair of programs as "tcp_srv.c" and "tcp_cli.c". Just the simplest version you have working, with hard-coded values for the message and IP/port values (IP = 127.0.0.1). Be sure to test with multiple clients at the same time.
sample of server output $ tcp_srv connected to client message received: //a horse is a horse, of course, of course//, count is 9 connected to client message received: //a horse MOO MOO is a horse, of course, of course//, count is 11 connected to client message received: //I came here to chew bubblegum and//, count is 7 control-c to stop $ sample of client output $ tcp_cli connected to server send phrase //I came here to chew bubblegum and// for counting the phrase has 7 words $ exit()s on it's own
Some suggested experiments and work to try after you get the basic version working are listed below. They are not required for this assignment, but will prepare you for the others to come.