The Chat Client

Your mission is to write a chat client.  It should work with the server that can be found at /home/rappleto/pub/Classes/CS228/Assignments/ChatClient/server.
You can start the chat server by simply typing the command and port number at the command prompt as shown below

 /staff/rappleto/pub/Classes/CS228/Assignments/ChatClient/server 7632


The server takes three kinds of messages.

  1. A message that has exactly four bytes which are 'Q', 'U', 'I', and 'T'.  This must be in all caps.  This cannot have a null character.  It must be just those four bytes.  This causes the server to close the connection.

  2. A message that starts with the four bytes 'N', 'A', 'M', or 'E'.  This must be in all caps.  This causes the server to change your name to whatever follows the 'E'.  Therefore the message "NAMEfred" will cause the server to change your name to "fred". Note there is no space.

  3. Any other message. This is just taken as a text for the server, which will reply.

A perfect client will do the following things in this order.

  1. Get the port number and hostname from the command line.

  2. Open a socket to the server.

  3. Send a "NAME" command to give the server your name.

  4. Get an answer back from the server. Print it to the screen.

  5. Loop

    1. Get Text from the keyboard

    2. Send it to the server.

    3. Read an answer back from the server. Print it to the screen.

  6. Until they type "quit" in any case

  7. Send the "QUIT" command in all caps

  8. Close the connection

  9. Exit

You get one point for every item on the list above.  You lose one point if it's turned in past Thursday Jan 31rd, and another point two day thereafter.