Fall 2018 CSE30264 Programming Assignment 3 - Online Chat Room


Total Points: 100 points
Goal: Program a Prototype of an Online Chat Room
Assigned: Oct. 3, 2018
Due: Oct. 31 , 2018 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: public messaging and direct 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 Public and Direct 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, and 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.
  7. Client generates a public key and sends it to the server. Note: multiple clients should be able to register at the same time.
  8. Server continues to wait for operation command from a client or a new client connection.
  9. Client goes into "prompt user for operation" state and prompts user for operation.
  10. Client passes operation (P: Public Message, D: Direct Messaging, Q: Quit) to server.
  11. Operation is executed as follows:
    1. P:
      1. Client sends operation (P) to broadcast a public message to all active clients (i.e., the 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. D:
      1. Client sends operation (D) 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 (Q).
      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, and the server replies with the user's public key
      6. Client then prompts for, encrypts, 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 decrypts it and 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. Q:
      1. Client sends operation (Q) 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 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:

(You can ignore the debug messages on the server. The top-left terminal is the online chat server and the rest are clients.)


Note: Please set the quality of the video to be 720p by clicking the gear in the lower right of the video.




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
TCP Port to UseName
41001Abrar Ahmed
41002Sam Alptekin
41003Alejandro Rafael Ayala
41004Jacob Beiter
41005James Bodeau
41006James Bonadonna
41007Patrick Bouchon
41008Elisabetta Caldesi
41009Meghan Cullen
41010Joseph DiMaria
41011Kevin Dingens
41012Quang Do
41013Steven Eisemann
41014Brandon Fite
41015Angelica Franco
41016William Fritz
41017Michelle Galbavy
41018Justin Garrard
41019Maria Gund
41020Jessica Hardey
41021Libertad Heredia
41022Sarah Hynds
41023Joshua Johnson
41024Grace Kopp
41025Kendyll Kraus
41026Sophie Lancaster
41027Jose Leon
41028Ale Lopez
41029Anthony Luc
41030Donald Luc
41031Kelly Malecki
41032Ryker McIntyre
41033Stephen Meisenbacher
41034John Meyer
41035Grace Milton
41036Josefa Osorio
41037Molly Pierce
41038Thomas Plummer
41039Allison Raines
41040Marcus Schimizzi
41041Madalyn Schulte
41042Benjamin Shadid
41043Abigail Shirey
41044Rita Shultz
41045Anna Smith
41046Kwan Ho Herman Tong
41047John Villaflor
41048Michael Wang
41049Daniel Wilborn
41050Roann Yanes