CNT 4704: Computer Communication Networks

Fall 2012

Home                      Lecture notes                        Assignment


Programming Assignment 1: TCP Client and Server implementation

(Due: Sept. 25th midnight via webcourse)

In this programming assignment, you will implement a client process process on your own machine (or on eustis Unix machine) and a server process on eustis.eecs.ucf.edu, respectively, to communicate with each other. The client and server will accomplish some very simple application-layer functions similar to HTTP. If you never log in to eustis.eecs.ucf.edu, your account should has the usual NID as your username and default password (Pyymmdd) with your birth year, month and day. If you use your own computer to compile and run the client process, you need to make sure your computer is inside campus network, or by setting up UCF VPN connection first. For how to set up VPN to UCF campus network, please check this website.

You can use either C, C++, or Java to program this project.

For secure remote connection to eustis Unix machine, you need to use SSH client software to do it. I recommend PuTTY for command-line remote login, and WinSCP for graphic-based FTP style file transfer. Both are free open-source software.

Your client program and server program 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).

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 following (put in a .zip file):

In the following, I will explain the details of commands that you need to implement.

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 C socket programming, see http://beej.us/guide/bgnet/

Programming notes

Here are a few tips to help you with the assignment:

        gcc -o client client.c  (or gcc -o server server.c)
      

Extra Credit (10 points).

For extra credit, rewrite your server to be a concurrent server - 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). With this concurrent server, you can open and close your client code as many times as you want, or run two client processes at the same time.