CSC 465 Assignment 2

 

Simple File Server: Transmission with Java Sockets

 

Due: Thursday, February 15, 2001

 

The goals of this assignment are to:

1.      Gently introduce you to Java programming, if you have not done this before.

2.      Demonstrate the relative ease with which TCP/IP-based client-server applications can be developed using sockets.

3.      Implement a stop-and-wait protocol for reliable data transfer over a channel with (simulated) bit errors (see textbook section 3.4, pages 185-190).  The errors have to be simulated because transmission actually occurs using the error-free TCP protocol.

 

You may work either individually or with one partner.  If you have no Java experience, try to hook up with a partner who has some.

 

The Problem.

 

Implement a simple FTP-GET-like service to transmit ASCII files from a server to a client.

 

Communication Protocol.

 

§         The client will transmit a request to the server containing the file name.  Pathnames are not required for this assignment, although they do not present any problem.  Assume the server is running in the same directory as the pool of files.

§         The server will open the file, then transmit a one-byte acknowledgement message to the receiver containing 'Y' if the file was successfully opened, and 'N' if it was not.

§         If the server was unable to open the file, the connection is obviously finished, so the client reports the error to the user and terminates. 

§         Otherwise, the server then proceeds to transmit file contents 8 bytes at a time in data packets, pausing after each transmission to receive an acknowledgement from the client that the packet was received. If the acknowledgement packet indicates damage, the data packet must be retransmitted.

§         Data packet is 9 bytes long.  The first byte is payload length in bytes.  This will be 8 for every packet except the last.  There is 12.5% chance that the file length will be a multiple of 8 bytes in length.  If this is true, send an extra packet with payload length value of 0.  After transmitting each packet, the server awaits an acknowledgement packet from the client.

§         The server will simulate transmission errors by randomly transmitting a "damaged" data packet. The error probability is specified as a server command line argument as an integer percentage in the range 0 (no errors) to 99 (99% errors, or .99 probability of damaging a packet).  Server will simulate damage by setting the payload length to 9.

§         Acknowledgement packet is one byte long.  If packet is OK, it will contain 'A' (for ACK).  If packet is damaged, it will contain 'N' (for NAK, or Negative AcKnowledge).  ACK and NAK packets are never damaged.

§         The client must of course create a file with the specified name and write to it the contents of each error-free packet as received.  After the last packet is successfully received and written, the client closes its connection and terminates.

 

NOTE:  The word "packet" by itself refers to a data packet.

 

 

The base program.

 

Don't panic if you don't know anything about programming with sockets!  The TCPClient.java and TCPServer.java programs from the textbook (the ones you compiled and ran last week) are available.

 

TCPClient.java accepts a line of text input from the keyboard and transmits it to the server through a TCP socket.  The server responds with the same text converted to upper case.  The client displays this result then terminates.

 

TCPServer.java accepts lines of text from clients (one at a time), converts the text to upper case and returns this result to the client.  The server process does not terminate on its own, but must be terminated by an outside action (such as Ctrl-C).

 

Java is an object-oriented language, but you will see that TCPClient.java and TCPServer.java are not!  You are free to utilize these programs as a basis for your solution, but are not required to.

 

 

Server command line arguments.

 

  1. Percentage of packets that will be damaged.  Integer in range 0-99.
  2. Whether or not packet tracing should be enabled. “T” to trace, “N” to not trace.  If not specified, “N” is assumed.
  3. Server communication port number (in range 5000-9999). If not specified, a default specified in your program is assumed.

 

Client command line arguments.

 

  1. Server identity (hostname, not IP address).  Examples: CHEK213-15.smsu.edu, csc.smsu.edu.  Use "localhost" if both client and server are running on the same machine.
  2. Name of file requested.
  3. Whether or not packet tracing should be enabled.  “T” to trace, “N” to not trace.  If not specified, “N” is assumed.
  4. Client communication port number (in range 5000-9999). If not specified, a default defined in your program is assumed. It must match the port number given to the server!

 

Client Output to Screen (after transmission complete).

 

  1. Total number of data packets received (correct plus damaged).
  2. Total number of packets damaged.
  3. Percent of packets that were damaged (#2 divided by #1, times 100).

 

The Trace Feature.

 

If data packet tracing is enabled for the server, it will display this for every packet sent:

filename : packet n sent status.

 

If data packet tracing is enabled for the client, it will display this for every packet received:

filename : packet n received status.

 

where:              filename is name of the file

                        n is packet number, starting at 1.  Not incremented until packet received OK.

                        status   is "OK" or "damaged"

 

 

TO TURN IN:

 

Call the server program sender.java, and the client program receiver.java. Copy your source files as well as an ASCII readme file to your ECCENTRIC server upload folder. The readme file must include your name(s) and explain implementation platform and program usage. The source code must be well structured and documented with comments.

 

REVISION PERIOD:

 

I am currently exploring and experimenting with various socket-related Java classes, including the abstract SocketImpl class.  I reserve the right to revise this assignment through February 8 for the purpose of utilizing alternative Java classes/methods for socket communication.  The protocol for file transmission itself as described in this document will not be changed.

 

 

Selected links to Java information:

 

My Fall 2000 CSC 132 home page http://www.cs.smsu.edu/~pete/csc132/index.html has links to several Java information resources, mainly from Sun Microsystems.  The most useful for reference purposes is the Java 2 Platform, Standard Edition, v 1.3, API Specification, http://java.sun.com/j2se/1.3/docs/api/index.html .

 


[ assignments | CSC 465 | Peter Sanderson | Computer Science | SMSU ]


Last reviewed: 1 February 2001

Peter Sanderson ( PeteSanderson@smsu.edu )