COSC 6377 : Computer Networks

Fall 2016

MW 1-230pm at F 154

Homework 1: Socket Programming

Due: 9/14/2015

In this homework, we will learn how to write basic networking applications using sockets.

Basic Sockets

Write a socket client and socket server. The programs should be called "sclient" and "sserver". The client sends a URL to the server, the server fetches the URL, stores it in the current directory and sends the name of the file to the client.

sserver supports a flag -p with which you can specify the port on which it listens for incoming connections and prints "waiting for clients". When a client connects to it, it prints "a client has connected" on stdout and responds to the client with an appropriate message once the requested task is complete. When the server has finished processing all the requests for the client, it should terminate the connection and wait for additional clients that might connect to it later. The processing the server does in our case is opening a socket to the webserver, downloading the content, and saving to the file.

Please use a basic socket program to connect to the webserver on port 80 and download the content using a GET request. Please do not use curl or other high-level library to download the content. The response will have HTTP header which you will need to delete before storing the file. A good way to test if your server is correctly downloading and saving the file is by having it fetch an image file. If you are able to view the saved image file, then the server is likely downloading and saving correctly. The server should save the downloaded content to a file in the local directory using md5 hash of the URL as the filename.

To make debugging easier, you may consider having the server print each message it receives and sends.

./sserver -p 5000
waiting for clients
a client has connected
received url: xxxxx
downloaded the page
storing to filename: yyyy
downloaded number of bytes: zzzzz
sent filename to the client: yyyyy
      

sclient supports the flags -p and -h with which you can specify the port and hostname for the server to which you want to connect. It also supports -u flag with which you can specify the URL for the page to be downloaded and stored by the server. Upon connecting to the server, the client prints "connected to the server at port xxx host xxx". It then sends appropriate message to the server.

./sclient -p 5000 -h bayou.cs.uh.edu -u AAAAA
connected to the server at port 5000 host bayou.cs.uh.edu
sent url: xxxxx
received filename: yyyyy
      

The best way to test these two programs is by running them in two different terminals and looking at the output from each program to make sure they are working correctly.

Protocol Design

You need to think about the semantics and format of the message that is exchanged between your client and the server. In your README, please document the protocol using a style similar to how RFCs are written. Please use an RFC for a simple protocol as an example.

Nice to have features

Most networked services can service multiple clients at the same time. It will be nice if your server can allow multiple clients to connect to it at the same time. You may need to use non-blocking IO or forks to accomplish this. If you are feeling adventurous, you should use non-blocking IO.

Many times a single network program is a client to some services and a server of different services. To get a first hand feel of the challenges in implementing such programs, You can combine the client and the server functionality into a single program. You can call your program "socketfun". Please describe how to run "socketfun" in your README.

Submission

TBD where to upload the code. Please include a README that describes the author, contact information, a short description of the software, instruction on how to run it, and finally limitations of your implementation.

To grade your submission, we will run your code on bayou so you should make sure your code runs on bayou. We will git pull, change to your hw1 directory and type "make". It should generate two executables sclient and sserver.