Principles of Web chat rooms

Source: Internet
Author: User

 

Currently, web chat rooms can be seen everywhere in web games, Forum blogs, and electronic malls.
There are many implementation methods for Web chat rooms, including Ajax-based implementation, comet (pushlet)-based implementation, and XMPP-based implementation, and the implementation of flash-based xmlsocket and remote shared object.

(1) Ajax-based implementation.
Ajax (Asynchronous JavaScript and XML, Asynchronous JavaScript and XML) is used to implement non-refreshing interaction between pages and servers. The basic principle of Using ajax to implement web chat rooms is: get data from the server through Ajax at intervals on the page, and then update the page display. This method is simple and clear, but the disadvantage is that the real-time performance is not high.

(2) implementation based on the comet technology.
Comet is a new Web application architecture. In applications developed based on this architecture, the server actively pushes data to the client program asynchronously without explicitly sending requests from the client. The comet architecture is very suitable for event-driven web applications and applications that require high interactivity and real-time performance, such as stock exchange analysis, chat rooms, and online web games.
Pushlet is a comet implementation (pushlet is an open-source comet framework): Under the servlet mechanism, data is pushed directly from the server's Java object to the client's page, without the help of any Java applet or plug-in. It allows the server to periodically update the client's web pages, which is different from the traditional request/response method.
Pushlet is based on HTTP streams. This technology is often used in multimedia videos and communication applications, such as QuickTime. In contrast to closing the HTTP connection immediately after loading the HTTP page, pushlet uses the HTTP stream method to continuously push new data to the client. During this period, the HTTP connection remains open. For details about how to implement this long keep-alive connection in Java, see http persistent connection provided by Sun and W3C http1.1 specifications.
(3) Implementation Based on XMPP protocol
XMPP (Scalable Message Processing site protocol) is an XML-based communication protocol designed for a timely communication system for instant messaging and online on-site detection. It facilitates quasi-real-time operations between servers. This protocol may eventually allow Internet users to send instant messages to anyone else on the Internet, even if the operating system is different from the browser. The predecessor of XMPP is jabber, an open-source network instant communication protocol. The famous open-source chat system server openfire is a Jabber server based on XMPP protocol.
You can use flash or ajax to interact with the Jabber server to implement the webim function,
(4) Implementation of flash-based xmlsocket
Flash Media Server is a powerful Streaming Media Server. Based on the rtmp protocol, it provides strong streaming media interaction functions. In the FMS, a remote shared object (mongodobject) mechanism is provided. The client can create and connect to the remote shared object on the server. Many clients can connect to the same remote shared object. Any client modifies the shared object, the server sends the modification information of the shared object to all clients connected to the shared object. This remote object sharing mechanism can implement the following functions: & middot; Remote Control of slide show & middot;
Text Chat & middot; online combat & middot; remote selection and playing of songs & middot; on-site auction & middot; customer service application.
Remote shared objects are suitable for implementing group chat in Web chat rooms. Create a remote shared object for each group. In this way, any user sends information to the Group, which can be automatically sent to all group members through the server.

It is impractical to use remote shared objects for single chat. For the implementation of single chat, we need to use socket. The client conducts private chat with other clients through the socket server. The chat information is forwarded through the socket server.
This is the most efficient way to implement web chat rooms.

Recently I have been studying chat systems, mainly based on pushlet server pushing technology. After the system is complete, I will share it with you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.