V22.0480-002 Special Topics: Networks

Final Project: Create a networking application using the socket interface over TCP to create a “chat application”.
For this assignment, you must create a “chat application” using the socket interface over TCP.   Here are the specifics:
         The client takes a single parameter, which is the name of the machine upon which the service resides.
         The client connects to the server.
         The server responds with either “Too many users logged on, try again later” or “Welcome to the chat server”.
         The user can either enter “chat commands” or text.   Normally, all text entered by the user is displayed to all other clients connected to the chat server.  However, the user can direct the text to only one specific user.
Here is the list of the chat commands:
=id name
         Informs the chat server of your identity.  You must enter that command as your very first command.  If you enter anything other than that command as your first data input, the server returns an error saying “Please identify yourself with the =id command first”.  The server also displays an error message is the name is already used, asking the user to use a different name.
         Prints out a comma-separated list all of the users using the chat server
=private name
         Directs the server to send all text only to the name you specify.  Otherwise, the text is sent to all users.
         Ends the private session created with the =private directive.
         Disconnects from the server.
         Sends the text to all users, unless you specified the =private directive.
The server sends a series of two-line messages.  The first line specifies “From name:”, where name is the user that sent the next line. The next line is either a message from the server or a message from another user on the chat service.
Here are the details:
Application layer:
         The client connects to the server.  The server responds with either “Too many users logged on, try again later” or “Welcome to the chat server”.
         If the server says, “Too many users logged on, try again later”, the client exits.  Otherwise, the client sends single-line, NULL-terminated strings to the server.  The client sends either text or a directive preceded by the ‘=’ character.  The client includes the new-line character in all strings (including the directives).  The directives are as specified above.
         All messages from the server are a NULL-terminated string that consists of two lines.  The first line has the form “From name:” where name is the user that has sent the next line.  The special name of “Server” means the message is from the chat server, which is followed by either a general status message or an error indication from a “=” directive.
Session Layer:
         All strings are NULL-terminated, and include the new-line character.  The directive “=bye” is sent to the server to indicate the client is terminating.  If the client sends the special character of  \” as the first character, then the server ignore the \ and takes the next character literally.  So, sending “\=bye” to the server instructs the server to treat “=bye” as text, not as a directive.
Presentation layer
         All data is sent in ASCII characters
Here is an example run.  Everything in italics is from the server.
./chat i5
Welcome to the chat server
Please identify yourself with the =id command first
=id Michael
From Server:
User Michael has logged on
From Server:
Wilma, Fred, Barney, Betty, Michael
Hello everybody
From Barney:
Hello Michael, I see you’ve joined in.  We were just talking about the new show, Smallville
From Wilma:
Yeah we all think it’s the greatest thing since “buffy “
From Server:
User Betty has logged off
From Server:
User Dino has  logged on
Wilma, Fred, Barney, Michael, Dino
From Fred:
Buffy is past tense.  Smallville is in now!
I guess that’s right, but how about Scrubs?  That’s on the same time as Smallville.
From Willma:
Scrubs stinks
=private Barney
Is Willma insane?  Scrubs is fantastic. 
From Barney (private to Michael)
She probably has never seen Scrubs.
Still, she probably doesn’t like Enterprise either
From Barney
Michael sent me a private note saying Willma was insane.
From Willma:
What you must turn in:
1. The C code that implements the client-side of the application.
2. The C code that implements the server-side of the application.
Due date: Tuesday, December  11