cs146a Project 1: TCP Client

Due : 2009-09-22 before 11:59 PM

This project must be written in C and must compile and run on one of the RHEL boxes in the berry patch (click here for a list of available machines).

Introduction

You will create a simple TCP network client with functionality similar to a stripped-down raw-TCP telnet. Your client will send text specified on the command line to a server, and then print to the console the response received.

Clients and Servers

We will use the term client to mean an application which initiates connections to servers and makes requests. Your web browser and instant message program are examples of clients. We will use server to mean an application which accepts connections from clients. Servers service requests from clients and send back responses.

Network Connections

You will learn about the socket abstraction for building network applications. A socket hides the protocol layer from the programmer, exposing instead a read/write interface that should be familiar if you have read from and written to files. In fact, sockets use the file descriptor interface.

You will use TCP to make the connection between client and server. TCP is a stream-oriented, reliable-transport protocol. This means that once a connection is established, requests and responses can be reliably sent and recieved using the connection's socket. We'll learn more about TCP when we study communication abstractions and networking.

Resources

Project Requirements

Your client will do the following when invoked:

  1. Create a blocking TCP socket and connect it to a specified host
  2. Send the input text given on the command line to the host over the socket, followed by two carriage returns (a carriage return is "\r\n")
  3. Read all data sent from the server and print it to stdout (the response must be printed completely verbatim without any formatting changes)
  4. After all output offered by the server has been received and printed, your client must exit (returning control to the shell).

A blocking client will wait indefinitely for a response from a server. A full-strength TCP client implementation is typically non-blocking, i.e., it handles asynchronous events by polling sockets to see if more data can be sent or received. A problem with blocking clients is that they can appear to hang if a server refuses to reply to its request; you can ignore this problem for now. We will learn how to write non-blocking network applications later in the term.

Invocation

Your client program will be named sc, and will be invoked on the command line like this:

./sc host port command

For example:

./sc www.brandeis.edu 80 "GET /"

Where it Must Run

We recommend that you develop on a Linux machine. You can log into any of the Brandeis CS department public machines to work, or you can work in the berry patch. You are also free to develop on your own computer, but be aware that in order to receive credit your assignment must compile and run on one of the RHEL machines in the berry patch.

Additional Requirements

Getting Started

Download and unpack sc.zip. At the Linux command line, you can unpack it with the following command:

unzip sc.zip

In Linux, to build sc, execute the following on the command line while in the sc directory:

make

This will build the sc binary, which you can run as described above. The skeleton sc.c does nothing, you will have to add to it all the required content to solve the assignment. As you are developing, you can rebuild sc simply by typing make on the command line again.

Tips and Suggestions

Collaboration

How to Hand In

Submission instructions have appeared in the FAQ.