4514 Project 2

Hangin' Out and Chatting in a Coffee Shop

Due date: Monday, February 15th, by Midnight

Index


Overview

You're tired after a long day. Your professors have been brutal with the homework, especially your Computer Networks prof. You need to unwind with your friends, but you also need a good jolt of caffeine so you can pull an all nighter and finish your programming assignments. Where can you do both? Why, the local coffee shop, of course!

This assignment serves as an introduction to client-server programming using the TCP/IP protocols (UDP and TCP). In this assignment, you will write on program, chat, that acts as both a client and a server. Your chat program will implement a simple two-person chat session. Your chat will act as a server when it is waiting for a connection (the analogy: you are just hangin' out in the coffee shop, waiting for someone to come talk to you. It will act as a client when it connects to someone else's chat which is waiting for a connection (the analogy: you spy your best bud sippin' some joe, so you cruise over to see what's up).

A key aspect of client-server programming: How does the client chat find out where the server chatis? That is, what transport-level address (Internet address and port number) should the client connect to?

One solution is to use a name server that dynamically maps service names into their transport-level addresses. We will supply you with a such a server, called the Central Perk (ala Friends), allowing you to register that you are hanging out as a chat server, waiting for chat client to connect to you (the analogy: the Central Perk is a room full of coffee-drinking, hard-working college students who are sick of classes and stuff and just want to shoot the breeze for awhile). Conceptually, the Central Perk is like the white pages in your phone book. A server registers the name and transport address of its service in the phone book, and clients use the phone book to map service names to transport addresses.

Your chat client must allow a user to communicate with the server (via list, add, delete, where commands, see below), hang out and wait for someone to connect (act like a server) and connect with someone else's chat program (act like a client). It must also be robust in the face of lost UDP messages to or from the server. Other than those basic functionalities, you are free to design your client in any way you want, including nicer interfaces for the chat sessions, easier commands to communicate to and from the server, an so on.

A bonus of 10 points will be rewarded to groups that have exceptional clients. Use your imagination! As a sample of a fairly unimaginative client, you can try out our chat at /cs/cs4514/proj2/chat. No warantees, etc on its robustness :-), but it should give you a sample of at least one possible client

.

You will use UDP to communicate with the server and TCP to communicate amongst the pairs of chat clients. See the class handout for more information on use of these protocols. See the samples for TCP and UDP client-server code samples.


Tools

You communicate with the Central Perk server via the below header file:

/* perk.h */
/* header file for Central Perk server */
/* version 1.0 */

#define PERK_HOST "wpi.wpi.edu"
#define PERK_PORT 4514
#define MAX_DESC 60		/* maximum description length */
#define MAX_NAME 10		/* maximum name length */
#define MAX_HOST 35		/* maximum host length */

enum type_list {list, where, add, delete, end, error}; 

/* contains the info for a chat room */
struct info {
  char name[MAX_NAME];		/* name of user */
  char description[MAX_DESC];	/* description of user */
  char host[MAX_HOST];		/* host user is on */
  int port;			/* port user is listening called */
  int when;			/* time last added, in sec since 01-01-70 */
};

/* message block understood by server.   Note, not all the fields
 * are used for each message */
struct message {
  enum type_list type;	/* the server command, message type */
  struct info person;
};

You can also copy the Central Perk header file from /cs/cs4514/proj2/perk.h.

The Central Perk server runs on host wpi.wpi.edu at UDP port 4514. You communicate with the server by passing a C structure struct message back and forth. The message contains a type field and an info field. The type field specifies a command to the server or a reply from the server. The info field may contain valid information, depending upon the command or the reply. Here are the specific commands understood by the server:

If the main Central Perk server crashes, please send email to cs4514_ta and ask that it be restarted. In the meantime, you can use an executable named perk in the /cs/cs4514/proj2 directory as a substitute server. It acts just like the main Central Perk server, but you must specify the port on the command line and you cannot use the main Central Perk port (4514).


Hints

The following system calls may be helpful: clearerr(3), gethostname(2), listen(2), close(2), getpwent(3), getuid(2), send(2), recv(2), getservbyname(3), gethostbyname(3), gethostbyaddr(3), getsockname(2), bind(2), socket(2), connect(2), accept(2), listen(2) and select(2).

Here are a few suggestions for development:

  1. Start early. Debugging client server code is sometimes difficult. Debugging client server code across separate hosts is even more difficult. Building a client to talk with a 3rd-party server is even more difficult, still. This is not to scare you, rather it is to encourage you to start as soon as possible in case you get "stuck."

  2. Work on each part separately. You can develop the chat of the client independently of the client part that communicates with the server and takes commands from the user.

  3. Start with the sample code. The best way to learn network programming (maybe any kind of programming) is through examples. Take the samples from the course web page (listen.udp, talk.udp, listen.tcp and talk.tcp) and go from there.

  4. Start small. Write a procedure that sends a datagram to the Central Perk server, and receives a datagram response from the server. The list command is the easiest one to get going at first. The server has some "canned" people hangin' out in it all the time so you should get some responses. Take a similar strategy for the chat part of the client.


Hand In

The main information I'd like you to have from the documentation standard is; author, date, project id, language, OS dependencies, description and building information. All this information should appear in a README file that accompanies your program.

Here is a sample of the information you should have:

Author:                         Mark Claypool
Date:                           1/21/00
Project ID:                     Project 2
CS Class:                       CS4514
Programming Language:           C
OS/Hardware dependencies:       None

Problem Description:            This program implements blah, blah, blah

How to build the program:       make

You will turn in your assignment using the "turn-in" program. Check here for information on how to turn in your assignments.


Return to 4514 Home Page

Send all questions to the TA mailing list.