CIS 457 Lab Assignment 7: TCP File Transfer

Objective: Gain familiarity with TCP (stream) sockets by writing a simple program.

Deliverables: The source code to your client and server, as well as screenshots or other recording showing your client and server running and then a diff command being run on the transferred file, in hard copy.

Teams: You should write your code individually, although you may of course discuss with classmates.

Grading: 10 points, as described below.

You may start this assignment with the intructor's echo code, which completes a large portion of it for you. You may also use your file reading code from project 1 if appropriate.

In this assignment, you are to write a file transfer server, and a client that interacts with it. These do not need to implement a full featured protocol such as sftp, instead, basic file transfer functionality is all that is needed. Specifically your programs must do the following:

  1. When started, the server should ask for a port number. Your server should then listen for connections on that port. (1 point)
  2. When started, the client should ask for an IP address and a port number. The client should connect to the server on the given IP address and port. (1 point)
  3. The client should prompt the user for a file name. Upon user input, the client should send the file name to the server. (2 points)
  4. The server should receive the message from the client, check if the requested file exists, and if so, send its contents. (2 points)
  5. The client should receive the contents of the file, save them to a new file, and then disconnect. (2 points)
  6. The server should still be running and able to accept another client connection (2 points)

You should test your program using the diff command. Run diff -s filename1 filename2 substituting the actual filenames of the original and new copies (if you test using the IP address, your program will work between client and server on the same computer).