Programming Assignment 1 -- Computer Networks
Computer Networks
Spring, 2001
Due: March 7 (midnight)
Write a connection-oriented client and server for the Internet family using sockets. The server will accept queries about files contained in its local file system. Clients can request information about the existence, contents, and other attributes of remote files.
The client. The client should read from standard input a sequence of command lines. Each line should be parsed into individual information requests, each of which is sent to the server. For each request, the client waits for a response and, when the response is received, writes the response to standard output.
The client program is run from the following command line:
rfq [ hostname [ port number ] ]
Use the local host as the default host. Use the RFQ_PORT defined below as the default port number.
A command line is in the form
options filename [ filename filename ... ]
where options is a string of characters, with each character representing
a type of information requested from the server. The command is terminated
by an end-of-line character. The possible options are:
t file type. ( "n" = normal, "d" = directory )
s file size in bytes.
m time of last modification.
d display contents. For a normal file, the server should simply read the file sequentially and pass it to the client, byte by byte. For a directory, the server should pass a list of the names of files contained in the directory.
c change directory. This will affect how the server interprets relative pathnames. It should be in effect only for this client session.
q quit.
The server. After accepting a connection from a client,
the server receives one message at a time from its network input (socket)
which represents a query for information about a file in the server's file
system. Messages should be in the form
options filename
If a requested file does not exist, or the server does not have
the required permissions to perform the requested action, the server should
return an error message to the client.
The server should listen on a port number defined in the server program, as in
#define RFQ_PORT _________
Java programmers should use the File object to obtain information about
a file. C programmers should use the stat system call.