CDA 4527: Computer Communication Networks
Fall 2007
Programming Assignment 1: TCP Client and Server implementation
(Due: Sept. 27, submit hard-copy report in class and other by email)
กก
In this programming assignment, you will implement a client process on my office Linux machine and a server process on Olympus Unix machine to communicate with each other. The client and server will accomplish some very simple application-layer functions similar to HTTP.
Your client and server should operate as follows. Your server runs first and it contains a buffer with an initial text string in it. The server process waits for connections from a client process using a server port number choosing by yourself (must be bigger than 1024).You should run your client program on cns.cs.ucf.edu, which is a Linux server in my office (I have create an account for each student), run your server program on olympus.acs.ucf.edu.
Your client operates by sending TRANSLATE, GET, STORE, and EXIT commands to the server. You should create a single client that is able to send any of the four commands above. If the client sends an invalid command, the server should respond by sending back a message "400 Command not valid."
When you submit this assignment to me, please submit the hardcopy of your report to me in class and email me the following (put in a .zip file):
In the following, I will explain the details of these commands.
Initially, when the server accepts the connection from a client, the server should display "server: got connection from client x.x.x.x" where x.x.x.x is the IP address of the client. It should also reply client with the message "Server is ready..." and be displayed at the client side.
TRANSLATE
This command requires the server process to translate the ASCII text sent from the client process to be in all upper-letter text and return back to the client process. The ASCII text sent from the client is ended with "." in the last line (similar as in the SMTP protocol). The server should reply "200 OK" and then return back the upper-letter text to the client. A client-server interaction looks like (shown at the client side):
c: TRANSLATE
s: 200 OK
c: Hello.
c: Nice to meet you!
c: .
s: HELLO.
s: NICE TO MEET YOU!
กก
At the server side, the server process should display "x.x.x.x sends TRANSLATE" when receiving this command. For all other commands, the server should also do this kind of display.
GET
This command asks the server to return back the text string saved in the buffer of the server process. When your server receives a GET command from a client, it should return the string "200 OK" (terminated with a newline), followed by the text. A client-server interaction with this command thus looks like (suppose the server's buffer contains a text "I don't think we're in Kansas anymore."):
c: GET
s: 200 OK
I don't think we're in Kansas anymore.
STORE
This command asks the server to store the text string that input from the client. When the server receives the STORE command from a client, it should return the acknowledgement "200 OK" (terminated with a newline) and then wait for client's input. The client input text is ended by "." after the last line of text (the saved string should not contain this ending line of "."). After saving the text, the server should return back the code "200 OK".
A client-server interaction with this command thus looks like:
c: STORE
s: 200 OK
c: One small step for man, one giant leap for mankind
c: Read my lips, no new taxes
c: .
s: 200 OK
EXIT
This command close the client program and inform the server to close, too. After receiving this command, the server should respond the acknowledgement "200 OK" to the client, display the "x.x.x.x sends EXIT", then close itself.
A client-server interaction thus looks like:
c: EXIT
s: 200 OK
Programming in C
For a detailed tutorial of socket programming, see http://beej.us/guide/bgnet/.
Programming notes
Here are a few tips to help you with the assignment:
gcc -o server server.c -lxnet
On cns.cs.ucf.edu, you don't need to put that "-lxnet" option
For extra credit, rewrite your server to be a concurrent server - that is a server that waits on the welcoming socket and then creates a new thread or process to handle the incoming request (the fork() system call).