CS 457 Project 1: Simple Chat Client

Version 1.0, Mon Aug 21
DUE DATE: Aug 31 at midnight

UPDATE (Mon, Aug 27): reference executables from the TA are now available: chat_32, and chat_64. Note that chat_32 should work on both 32 and 64-bit machines, whereas chat_64 only works on 64-bit machines. Don't forget to change file permissions after download to make it executable. In Linux simply type:

$chmod a+x chat_32    // make the file executable by all
$./chat_32 - h              //run the program with -h to see the available options

Introduction

In this project you will use socket programming to implement a simple chat client.

This assignment will consist of one program which acts as both the client and the server. The program will communicate simple messages back and forth starting with the client sending to the server. Your code must work on the Linux machines in the 120 Linux Lab. Test your code by running your client on one machine and your server on another. Chat will be strictly back and forth, after sending a message, the program waits to receive a message before sending again (see example interaction). Messages may be up to 140 characters and should be checked by the program. Print an error message and ask for a new message if the user inputs more than 140 characters. You will write three files for this assignment: chat.(c|cpp), README, makefile. Requirements for each are stated below.

You may work alone or with one other person. If you are working with another team member, both of you must let the TA know by e-mail who you are working with by Monday, August 27 at 5pm.

Chat Example:

Server Client
$./chat
Welcome to Chat!
Waiting for a connection on 192.82.47.232 port 3360
Found a friend! You receive first.
Friend: hello!
You: Hi! How are you?
Friend: I'm great.
You: That's good. Ok, bye!
^C

$./chat -p 3360 -s 192.82.47.232
Connecting to server... Connected!
Connected to a friend! You send first.
You: hello!
Friend: Hi! How are you?
You: I'm great.
Friend: That's good. Ok, bye!
You: ▐

Input too long example:


$./chat -p 3360 -s 192.82.47.232
Connecting to server... Connected!
Connected to a friend! You send first.
You: hello! I just got back from lake Chargoggagoggmanchauggagoggchaubunagungamaugg. Next year, we are going on a trip to the Mississippi river to go fishing!
Error: Input too long.
You: Hello!
Friend: Hi!
You: ▐

chat.(c|cpp) Requirements

The program is invoked in two ways:

$./chat
$./chat -p 3790 -s 192.168.47.232
Where the -p flag indicates the port to connect to and the -s flag indicates the IP address of your friend.

Without any arguments, the chat program acts as a server, prints out the port it is listening on and waits for a connection.
With arguments, the program acts as a client connects to a waiting server using the information provided.
With one argument, the program prints an error and exits.
The arguments may be in any order and should be sanity-checked.

Server
  1. Set up a TCP port and listen for connections (print out IP and PORT listening on).
  2. Accept connection from client
  3. Block to receive a message from the client.
  4. Receive message and print to screen.
  5. Prompt the user for a message to send.
  6. Send the message to the client.
  7. GOTO step 3.
Client
  1. Set up a TCP connection to the server on the IP and port specified.
  2. Prompt the user for a message to send.
  3. Send the message to the server.
  4. Block to receive a message from the server.
  5. Receive message and print to screen.
  6. GOTO step 2.
The programs will continue until terminated (^c) by the user.

README

You must include a readme that explains to a potential user the process of invoking your program. You may assume that the user is familiar with using terminal programs. Also include questions that you asked the TA and the answer to those questions and any assumptions you have made along the way (hint: ask before assuming!).

If you are part of a team, your readme should include both names and which parts each person significantly contributed to. Both team members should be able to explain any part of the code in the program.

makefile requirements

You must include a makefile that produces an executable called chat.

Interaction Requirements

Programs will be randomly paired up and will have their client and server tested with the other's client and server. To make this possible, you must follow the packet format specified below.
Version (16 bits, Binary) Str. Length (16 bits, Binary)
Message (up to 140 bytes, ASCII)

Where the Version is always 457, the Str. Length is the length of the message in bytes, and the message follows immediately afterwards. To test this, your TA has written a test client and a test server so that you can check your interactions. The executable will be available on this site by Monday, August 27 at 5pm.

Grading

  • No credit will be given to a program that fails to compile on the department linux machines.
  • 5% Makefile included and compiles programs without errors.
  • 5% README included and contains enough information to run program.
  • 10% input flags accepted in any order and sanity-checked.
  • 10% Program produces an error and asks for another message if the message is over 140 characters.
  • 10% Program uses network-to-host and host-to-network.
  • 10% Programs work with other team's randomly chosen client and server.
  • 45% Program passes send/receive test cases.
  • 5% Output formatting looks like the example.

Turn in your assignment by e-mailing a tar archive of the files to [akshah at cs dot colostate dot edu]. Be sure that the files are at the root of the archive and not in any folders. Include your last name and the last name of your team member, if any. Only one file per team needs to be submitted.