Description
Introduction to Computer Networks
Objectives:
- Implement a client-server network application
- Learn to use the sockets API
- Use the TCP protocol
- Refresh programming skills
The Program:
Design and implement a simple chat system that works for one pair of users, i.e., create two programs: a chat server and a chat client. The final version of your programs must accomplish the following tasks:
- chatserve starts on host A.
- chatserve on host A waits on a port (specified by command-line) for a client request.
- chatclient starts on host B, specifying host A’s hostname and port number on the command line.
- chatclient on host B gets the user’s “handle” by initial query (a one-word name, up to 10 characters). chatclient will display this handle as a prompt on host B, and will prepend it to all messages sent to host A. g., “ SteveO> Hi!!”
- chatclient on host B sends an initial message to chatserve on host A : PORTNUM. This causes a connection to be established between Host A and Host B. Host A and host B are now peers, and may alternate sending and receiving messages. Responses from host A should have host A’s “handle” prepended.
- Host A responds to Host B, or closes the connection with the command “\quit”
- Host B responds to Host A, or closes the connection with the command “\quit”
- If the connection is not closed, repeat from 6.
- If the connection is closed, chatserve repeats from 2 (until a SIGINT is received).
Notes:
- For your C implementation, read Beej’s Guide. It has everything you need for this assignment. You will probably learn the most about socket programming by using C.
- If you are using Python, check http://docs.python.org/release/2.6.5/library/internet.html,
- If you are using Java, check http://docs.oracle.com/javase/tutorial/networking/sockets/index.html.
- It’s OK to hard-code host A’s handle.
- It’s OK to implement this system so that it requires the two users to take turns sending messages, i.e., when a user sends a message, s/he must wait for a response before sending the next message.
- When debugging, don’t use the well-known port numbers, because these will already be in use. I’d suggest using 30020 or 30021, though other students may be using these when you’re on the servers.
- If you use additional include-files or make-files, be sure to include them in your .zip file.
- You can test these programs using just one computer. Start the server, then start the client in a new window. You can then switch back and forth between the two terminal windows.




