Fall 2019 CSE30264 Programming Assignment 3 - Online Chat Room


Total Points: 100 points
Goal: Program a Prototype of an Online Chat Room
Assigned: Oct. 9, 2019
Due: Extended to Nov. 6 , 2019 by the beginning of class
Grouping: Completed by a group


Background

In this programming assignment, you will implement the client and server sides of an "online chat room" application. You can choose to use either TCP or UDP in your implementation. In this application, the client determines the operation to be performed: broadcast messaging and private messaging. Even though only one port is being used, the server should be able to accept multiple simultaneous client connections. The server should respond appropriately to the specific command send by the client. The specifics of the protocol are detailed in this handout. You are free to reuse part of your programs in the programming assignments 1 and 2 to finish this programming assignment. Note: please refer to appendix A for the port number assigned to you (the same as PG1).

Type of Messages

In this assignment, we define two types of message frames: 1) data message and 2) command message. A data message is the message exchanged between clients (i.e., the Broadcast and Private messages described in the following online chat room protocol). A command message is the message exchanged between the client and server (e.g., operation, acknowledgment, confirmation messages described below). In your implementation, you can define your own message format to encode the message type. For example, you can use the first character of the message to distinguish between the two types of messages (e.g., "C" for command message and "D" for data message).

Note: In your implementation, the sender is responsible for encoding the type information into the message frame and the receiver is responsible for extracting the type information from the message and performs accordingly. (Refer to Technical Instruction section for more details.)

Online Chat Room

  1. Server opens a port, creates the TCP/UDP socket, goes into "wait for connection" state, and actively listens for socket connections. Hint: Please read the Technical Instruction Section below for details.
  2. Client logs into the system by connecting to the server on the appropriate port.
  3. Client sends the username.
  4. Server checks to see if it is a new user or existing user and requests a password. Note: Store users and their passwords in a file rather than in memory (otherwise the credentials will get lost once the server program is terminated).
  5. Client sends the password.
  6. Server either registers a new user or checks to see if the password matches. Server then sends the acknowledgment to the client. Note: multiple clients should be able to register at the same time.
  7. Server continues to wait for operation command from a client or a new client connection.
  8. Client goes into "prompt user for operation" state and prompts user for operation.
  9. Client passes operation (B: Broadcast Messaging, P: Private Messaging, H: Show History, X: Exit) to server.
  10. Operation is executed as follows:
    1. B:
      1. Client sends operation (B) to broadcast a broadcast message to all active clients (i.e., clients who successfully log into the system but has not exited yet).
      2. Server sends the acknowledgment back to the client to prompt for the message to be sent.
      3. Client sends the broadcast message to the server.
      4. Server receives the message and sends that message to all other client connections. Note: The server should keep track of the socket descriptors it has created for each client since the program began running. You can decide how to implement this tracking function.
      5. Server sends confirmation that the message was sent. Note: You can decide the content/format of the confirmation.
      6. Client receives the confirmation.
      7. Client and server return to "prompt user for operation" and "wait for operation from client" state, respectively.
    2. P:
      1. Client sends operation (P) to leave a message to a specific client.
      2. Server sends the list of current online users. Note: The server should keep track of the usernames of all online users (i.e., users associated with active clients) since the program began running. You can decide how to implement this tracking function. We assume that any client can go offline by using operation (X).
      3. Client receives the list of online users from the server.
      4. Client prompts the user for and sends the username (of the target user) to send a message to.
      5. Client sends the username to the server.
      6. Client then prompts for, and sends the message to be sent.
      7. Server receives the above information and checks to make sure the target user exists/online.
      8. If the target user exists/online, the server forwards the message to the user, which displays the message. The server should do this by sending the message to the corresponding socket descriptor of the target user.
      9. Server sends confirmation that the message was sent or that the user did not exist. Note: You can decide the content/format of the confirmation.
      10. Client receives the confirmation from the server.
      11. Client and server return to "prompt user for operation" and "wait for operation from client" state, respectively.
    3. H:
      1. Client sends operation (H) to view the chat history.
      2. The chat history should be stored in a file on the server that keeps track of all previous chat messages received and sent by the client. The file is stored on the server rather than on the client so that the user cannot modify or delete the chat history. The file should be created upon user registration. For example, when user Alice registers, the server will create a file "Alice.chat" to store her chat history.
      3. Each chat history entry should include [Timestamp] [Type of Chat (B or P)] [Source and Destination] and [Message Content]. The timestamp is the moment when a client sends or receives a message. In this assignment, you can use the timestamp of the server when it receives the message of the client, given all four student machines are synchronized on a high-speed LAN with negligible communication delay. [Source and Destination] refers to the sender and receiver of the message. For broadcast messages, you only need to specify the sender.
      4. When receiving the (H) command, the server sends the chat history to the client.
      5. The client receives and then displays the chat history on screen.
      6. Client and server return to "prompt user for operation" and "wait for operation from client" state, respectively.
    4. X:
      1. Client sends operation (X) to close its connection with the server and end the program.
      2. Server receives the operation and closes the socket descriptor for the client.
      3. Server updates its tracking record on the socket descriptors of active clients and usernames of online users.
      4. Client should close the socket and return.

Note: If it is not explicitly specified, the client and server will return to "prompt user for operation" and "wait for operation from client" state, respectively after a successful operation and wait for the next operation.

Technical Instructions


General Notes

Server Side Design

The server is responsible for handling the connection request from multiple clients, processing the request, then looping back to handle further requests from any client. The server binary should be named chatserver.

The server should listen on the specified port number [refer to Appendix for the port number for your group] that is given by the command-line argument. Your server should bind to the port and then listen for incoming client connections. You may decide if you would like to allow timeouts for better responsiveness but any sort of a timeout is purely optional. You may want to allow for port reuse for quicker recovery after a crash.

Once a new client request arrives, your server should use the accept function to create a new client socket. Your server should be invoked as follows:
./chatserver Port

Client Side Design

The client is responsible for initiating a connection to a server. Once connected, the client code should prompt the user for an operation (B, P, E), and should transmit the operation to the server. Your client executable should be named chatclient. Your client should be invoked as follows:
./chatclient Server_Name Port Username

The first argument is the hostname of the server to connect to (this will depend on what machine you start your server code on). The second argument is the port number. The third argument is the username for login.

Demo:


Download the Demo.

Submission

Submit a gzipped tar file of your entire assignment package to your dropbox/program3 directory. The archive must include the following:

Grading Rubric


Appendix A

Table 1. Port Assignments
Port to UseName
41001 Samuel Battalio
41002 Bailey Blum
41003 Paul Brunts
41004 Kathleen Capella
41005 Jacques Charboneau
41006 Thomas Clare
41007 Jack Conway
41008 Matthew DaDamio
41009 Megha Devaraj
41010 Michael Eisemann
41011 Michael Erdenberger
41012 Nicholas Fahrney
41013 Clare Fallon
41014 Patrick Fischer
41015 Chris Foley
41016 John Fox
41017 Luke Fraser
41018 Owen Gallahue
41019 Jorge Garcia
41020 Elizabeth Genovese
41021 Gabrielle Good
41022 Joseph Gripenstraw
41023 Katherine Hecht
41024 Jack Hill
41025 Julia Hughes
41026 Carson Lance
41027 Connor Laracey
41028 Bailey Logan
41029 Horacio Lopez
41030 Catherine Markley
41031 Imari McKinney
41032 Sean Michalec
41033 Ralph Moran
41034 David Odun-Ayo
41035 Jewon Oh
41036 Cole Pickford
41037 Brendan Raimann
41038 Christopher Ray
41039 Daniel Riehm
41040 Conor Rinehart
41041 Francis Schickel
41042 Matthew Siciliano
41043 Richard Stefanik
41044 Emily Strout
41045 Blake Trossen
41046 Justin Virgadamo
41047 Trenton Wray
41048 Jillian Ybanez
41049 Logan Yokum
41050 Christina Youn