/Web-Instant-Messenger

Web-Based Multi-Client Instant Messenger

Primary LanguageJava

WebInstantMessenger

Web-Based Multi-Client Instant Messenger

Members

Xincheng Huang - Client

Zhanghao Chen - Server

Project Objective

The objective of this project is to design an web-based multi-client instant messenger.

A client runs in a web browser, which is implemented in a webpage dynamically generated by Javascript. The server opens a listening socket that will be used to accept incoming connections from users signing up for the first time. The server is multithreaded so as to handle multiple online users. Once the TCP connection established and the service socket created, the server processes the Ajax requests submitted by the client browser.

Code Structure

HTTPServer.java

HTTP server which opens a chat server, listens to client requests, and opens new threads to process the requests.

HTTPServerThread.java

Thread of the HTTP server serving a single client.

HTTPRequest.java

Encapsulation of the HTTP request message, provides methods to parse it.

HTTPResponse.java

Encapsulate the HTTP response message, provides methods to generate it.

ChatServer.java

Chat server managing chatting service.

ChatGroup.java

Responsible for the management of chatting groups in the system.

ChatMessageGroup.java

Responsible for the management of the members and messages in a chatting group.

AvailabilityCheck.java

Check client availability at intervals.

Commnication Protocol

LOGIN

Request

URI: chat.do/<user name>

Request Body: M_LOGIN

Resonse

Response Body: if success, same as UPDATE with empty, otherwise M_FAIL (duplicate name, try another one)

UPDATE

Request

URI: chat.do/<user name>

Request Body: M_UPDATE + <sequence number>

Resonse

Response Body: M_SUCC + chattingStatus + <member list> + “|” + <message list>

  • Notice:
  1. Sequence number is used to keep track of how many messages the user has received in the conversation, it functions similarly to the sequence number in TCP connection

  2. Once connected, an sequence number will be sent by the server (see CONNECT)

  3. When the user does not join any conversation, <message list> will be empty

  4. <member list> is in the form of a JSONObject, each entry of which is a mapping set of  the form (username : chatting status)

  5. <message list> is in the form of a JSONArray, each entry of which is a list of the form {username, message}

  6. org.json is the JSON processing library I use

CONNECT

Request

URI: chat.do/<user name>

Request Body: M_CONNECT + <peer name>

Resonse

Response Body: M_SUCC + <sequence number> + '|" + <member list of the conversation> if success, M_FAIL if group maximum size reached

EXCHANGE

Request

URI: chat.do/<user name>

Request Body: M_EXCHANGE + <message>

Resonse

Response Body: M_SUCC

DISCONNECT

Request

URI: chat.do/<user name>

Request Body: M_DISCONNECT

Resonse

Response Body: M_SUCC

LOGOUT

Request

URI: chat.do/<user name>

Request Body: M_LOGOUT

Resonse

Response Body: M_SUCC