Client/server programming exercise

Objective:    The objective of this exercise is to learn how to use the BSD Sockets libraries to write simple client/server applications for the Internet.

Preparation:    Read the tutorial on socket programming.

Exercise:   Write a simple FTP server and client using the TCP sockets library on Linux (Unix). You may start with the sample C client code and C server code provided here. Or, you may prefer the C++ client code and the C++ server code. This code shows how to use command line parameters and the use of the sockets library for a simple stateful server that returns a message to the client that tells the number of times that it has been contacted. For your simple FTP client and server, use the following specifications:

Client specification:    Your client should accept as a parameter from the command line: 1) the name of the file to be transferred, and 2) the address of the server. If there are three parameters on the command line, then the third parameter is the port number to connect to at the server side. The order of the parameters in the command line should be in the order mentioned above. You do not have to do error checking on the user's behalf to be sure that the user types the parameters in the correct order.

The client should send the filename in a TCP message to the server. Then the client should receive messages from the server and print all lines to stdout until no more lines are received. (Note that you can write the client output to a file by redirecting the output from the command line in Unix.)

Server specification:    Your server should accept as a single optional parameter from the command line the number of the port to listen to. The server should receive the name of the file from the client. If the file cannot be opened in the current directory, then the server should return the string "File not found." to the client. If the file can be opened, then the server should send each line of the file to the client until the end of the file is reached. After sending the file, the server should close the file and then continue to listen for more client requests, in an iterative fashion. Your server should run indefinitely until you kill it (using control-C at the command line or using kill -9).

You server should print out appropriate informative messages as it executes. You should do appropriate error detection for the TCP socket calls. You may test to program to see if it runs correctly by performing a "diff" on the original file and the one that has been received via your FTP program. For convenience, you may assume that the files transferred by your program have line lengths that are 80 characters or less.

If you have any questions concerning this programming assignment, please feel free to ask me.

Grading:    Good programming practices will be taken into account when grading so make sure your program is clean and organized, and include plenty of comments.

You may wish to add a menu to the client side of your code so that it behaves more like regular ftp. If you do this, then since the name of the file is specified when either the put or get commands are used, the command line parameters for your client should include the address of the server and the port number to connect to at the server side only. The menu functions can include functionality such as:

Turn in:    A hardcopy of this program with your other homework. Also, send a copy of the source code of your program as email to aapon@uark.edu with the subject line: client/server exercise.