Computer Networks - CSE 30264 - Programming Assignment 4


Total Points: 100 points
Goal: Program a Prototype of an Online Chat Room
Assigned: Nov. 1, 2017
Due: Nov. 20, 2017 by the beginning of class
Grouping: Completed by a group


Background

In this programing 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: message broadcasting 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, 2, and 3 to finish this programming assignment. Note: please refer to appendix A for the port number assigned to your group for the assignment.

For the assignment, you will turn in a gzipped tar file to your dropbox. The gzipped tar file should contain:

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, acknowledgement, 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 of encoding the type information into the message frame and the receiver is responsible of 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 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 password.
  6. Server either registers a new user or checks to see if the password matches. Server then sends acknowledgement 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: Message Broadcasting, P: Private Messaging, E: Exit) to server.
  10. Operation is executed as follows:
    1. B:
      1. Client sends operation (B) to broadcast a message to all active clients (i.e., the clients who successfully log into the system but has not exited yet).
      2. Server sends the acknowledgement 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 and prints 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 (E).
      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 then prompts for and sends the message to be sent.
      6. Server receives the above information and checks to make sure the target user exists/online.
      7. If the target user exists/online, the server forwards the message to the user. The server should do this by sending the message to the corresponding socket descriptor of the target user.
      8. 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.
      9. Client receives the confirmation from the server and prints it out.
      10. Client and server return to "prompt user for operation" and "wait for operation from client" state respectively.
    3. E:
      1. Client sends operation (E) 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 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


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



General Notes