Web-Based Multi-Client Instant Messenger
Xincheng Huang - Client
Zhanghao Chen - Server
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.
HTTP server which opens a chat server, listens to client requests, and opens new threads to process the requests.
Thread of the HTTP server serving a single client.
Encapsulation of the HTTP request message, provides methods to parse it.
Encapsulate the HTTP response message, provides methods to generate it.
Chat server managing chatting service.
Responsible for the management of chatting groups in the system.
Responsible for the management of the members and messages in a chatting group.
Check client availability at intervals.
URI: chat.do/<user name>
Request Body: M_LOGIN
Response Body: if success, same as UPDATE with empty, otherwise M_FAIL (duplicate name, try another one)
URI: chat.do/<user name>
Request Body: M_UPDATE + <sequence number>
Response Body: M_SUCC + chattingStatus + <member list> + “|” + <message list>
- Notice:
-
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
-
Once connected, an sequence number will be sent by the server (see CONNECT)
-
When the user does not join any conversation, <message list> will be empty
-
<member list> is in the form of a JSONObject, each entry of which is a mapping set of the form (username : chatting status)
-
<message list> is in the form of a JSONArray, each entry of which is a list of the form {username, message}
-
org.json is the JSON processing library I use
URI: chat.do/<user name>
Request Body: M_CONNECT + <peer name>
Response Body: M_SUCC + <sequence number> + '|" + <member list of the conversation> if success, M_FAIL if group maximum size reached
URI: chat.do/<user name>
Request Body: M_EXCHANGE + <message>
Response Body: M_SUCC
URI: chat.do/<user name>
Request Body: M_DISCONNECT
Response Body: M_SUCC
URI: chat.do/<user name>
Request Body: M_LOGOUT
Response Body: M_SUCC