Font Size: a A A

Design And Implementation Of Online Chat System Based On WebSocket Protocol

Posted on:2017-12-02Degree:MasterType:Thesis
Country:ChinaCandidate:F X DuFull Text:PDF
GTID:2348330491964432Subject:Software engineering
Abstract/Summary:PDF Full Text Request
With the development of electronic commerce, online shopping has become one of the main ways of consumption, and communicating with sellers has become one of the most effective ways to get information.At present, chat systems of electric business platforms are realized mostly based on HTTP polling and long polling. In order to get new information in time, the browser needs to send HTTP requests to the server frequently and the protocol header occupies hundreds of bytes in each interaction. In addition, the arrival time of new message is uncertain so that a large proportion of requests cannot get new information. The WebSocket protocol provides a way to solve above problems. It defines a full duplex, asynchronous connection between server and browser, the protocol header occupies up to 14 bytes in the process of communication. If we can realize the chat system based on WebSocket protocol, we can solve the above problems effectively. However, when we apply the WebSocket protocol to online chat system, there are three major difficulties, such as maintaining the WebSocket connection, sharing sessions in the cluster and processing messages. It's hard to maintain the WebSocket connection because many cases may fail the connection. And it's hard to share sessions in cluster because sessions are stored in memories of servers. Besides, it's difficult to process messages for servers because all messages from users are to be handled by servers.After finguing out the reasons, this thesis takes following measures to solve above difficulties:apply heartbeat mechanism, reconnection mechanism and failure monitoring mechanism to reducing the WebSocket connection failure; realize sharing sessions with the help of Nginx and Memcached, Nginx is used to balance requests and Memcached is used to store session distribution information; ensure the accuracy of processing messages in a variety of ways, such as message confirmation, retransmission, compensation and saving messages to the database.Based on above measures, this thesis realizes the chat system and verifies the performance of it through experiments. This thesis solves the existing problems of present chat systems:server cannot take the initiative to push messages; lots of invalid interaction exists between server and browser; HTTP header occupies a lot of bandwidth. In addition, this thesis demonstrates the possibility of applying WebSocket to real-time systems and provides some help for the further application of WebSocket protocol.
Keywords/Search Tags:WebSocket, session sharing, cluster, message forwarding
PDF Full Text Request
Related items