HW 2: TCP Info Server

Info Server

CS 494/594 Homework #2
Bart Massey
Due 14 June 2012 5PM
DRAFT

It is sometimes handy to find out some basic information from a remote server. The easiest way to support this is to make a TCP connection, request the information in ASCII, and read the ASCII response.

For this assignment, you are to write a TCP server in C that will listen on port 11466. When a client connects, the server should read a line containing an ASCII command from the client, discard any line ending (CR, LF, or CRLF), close the connection from the client (half-close), respond with a line containing the ASCII response terminated with CRLF, and close the connection to the client.

The possible commands are:

  • "VERSION": Respond with "1".
  • "DAYTIME": Respond with a date and time in RFC 822 format.
  • "RANDOM": Respond with a pseudorandom number between 0 and 9 inclusive, in decimal.
  • "ECHO <stuff>": Respond with <stuff>. In other words, respond with everything after the first space and before the line ending.

Any other input should result in the connection being silently closed. Commands are case-sensitive.

You may choose to modify the TCP echo server we wrote earlier in class for this assignment. You can get a copy of the TCP echo server source as a ZIP archive from http://github.com/BartMassey/tcp-echo/zipball/master. You can also clone git://svcs.cs.pdx.edu/git/tcp-echo.git if you are familiar with Git.

You must submit the following:

  • Your server C source code, together with any other files needed to try it out.

  • A README.homework file containing a writeup in plain text of not more than 1000 words describing what you did, how it worked, and anything else you think we should know.