COSC 6377 - Computer Networks

Fall 2012

MW 1:00-2:30pm at PGH376

InstructorOmprakash Gnawali

Homework 1 : Network server and client

Due: September 19, 2012

In this assignment, we will write two programs: a client and a server. They will communicate with each other across the network using sockets.

We are going to build a client and server to transfer files across the network. You execute a server. Then, you execute a client, potentially on a different machine. The client will send a request to the server for a specific file. The server, upon receiving this request, will search for a file with the name in its current directory, and transfer the file to the client.

The first program is called file_server, which is a socket server. The server will be launched like this:

./file_server listen_port
Once launched, the server waits for connection on the given port.

The second program is called file_client, which is a socket client. The client will be launched like this:

./file_client server_ip server_port serverfilename savefilename

Once launched, the client program connects to a server running on the given IP address and port. To find the IP address of the server, log in to the server machine, and type ipconfig. The third parameter is the name of the file the client wants to download from the server. The fourth parameter is the file to which the client will save the downloaded content.

It is most convenient to test these programs by opening two terminal windows on the same machine. That way, you can run the client in one window and run the server in the other window. Here is an example execution.

On server window:

./file_server 12345

Listening for incoming connection...

A client connected.

Client requested file: test.txt

Sending file: test.txt

Completed transfer: test.txt

Listening for incoming connection...

A client connected.


On client window:

./client_server 12345 test.txt saved.txt

Connecting to server IP port 12345

Requesting test.txt

Downloading the file

Saving the file to saved.txt

Transfer complete

Before you proceed to the next step, make sure your server and client are able to exchange a text file and a binary file, e.g., an image. Please verify that the file on the server and the same saved by the client are identical. You might find md5sum command handy to verify that the two files are identical.

Concurrent File Server

Above we showed how a client will connect to a server to download a file. We want you to use either pthreads or non-blocking IO to enable the server to serve multiple clients at the same time. The best way to test this is by opening three terminals. On the first terminal, launch the server as shown above. On the second terminal, launch the client and have it request a big file, something that will take a minute to download. In the meantime, open another terminal, and launch the client and request a small file from the same server. You can use printf on the server to make sure it is able to accept new connection while it is transferring file to the first client. If the second client is able to download the file while the first client is still downloading the file, you have just written your first server that can concurrently serve multiple clients.

We want your server to be able to accept a maximum of 5 simultaneous connections. You can test it by launching six clients that connect to the same server. The sixth client should not be able to establish a connection to the server.

Compiling and Running

It is perfectly fine for you to work on your own Linux machine. We have provided each student with an account on a Linux machine called Each student has also been assigned port numbers. Please launch your server on one of these port numbers. Regardless of where you do your assignment, your assignment must compile and execute on bayou.


Put your source code into a folder with the name: uhid_hw1, where uhid is the prefix of your email address. There should be a single Makefile in that directory. When we run make on that directory, it should produce two executables file_server and file_client. Put a README.txt in the directory describing anything unusual (e.g., limitations) of your implementation. Then, zip the directory and upload the zip file using Blackboard.