Pushlet-open-source comet framework-implement server-side push technology

Source: Internet
Author: User

Pushlet-open-source comet framework

Pushlet is an open-source comet framework. It has a lot to learn from in terms of design and has great reference value for developing lightweight comet applications.

Observer Model

Pushlet uses the observer model: the client sends a request and subscribes to events of interest. The server assigns a session ID for each client as a tag, the event SOURCE sends new events to the subscriber's event queue in multicast mode.

Client JavaScript Library

Pushlet provides Ajax-based JavaScript library files for "server push" in long polling mode, and IFRAME-based JavaScript library files for "server push" in stream mode ".

The javascript library has done a lot of encapsulation work:

  1. Define the communication status of the client:STATE_ERROR,STATE_ABORT,STATE_NULL,STATE_READY,STATE_JOINED,STATE_LISTENING;
  2. Save the session ID allocated by the server. The session ID is attached to each request after the connection is established to indicate the identity;
  3. Providedjoin(),leave(),subscribe(),unsubsribe(),listen()And so on
    APIS for page calls;
  4. Provides JavaScript function interfaces for response processing.onData(),onEvent()...

Web pages can easily use the APIS encapsulated by these two JavaScript library files to communicate with the server.

Format of client-server communication information

Pushlet defines a set of information formats for communication between customers and servers, in XML format. Defines the types of requests sent by the client:join,leave,subscribe,unsubscribe,listen,refreshAnd RESPONSE event type:data,join_ack,listen_ack,refresh,heartbeat,error,abort,subscribe_ack,unsubscribe_ack.

Server-side event queue management

Pushlet is implemented using Java Servlet on the server side. Its data structure design framework can still be applied to backend clients written in PHP and C.

Pushlet allows the client to select the stream, pull (long polling), and polling modes. The server performs different processing when reading the event queue (fetchevents) according to the method selected by the customer. In "polling" ModefetchEvents()Will return immediately ." Stream "and" pull "modes use the blocking mode to read events. If it times out, it will send a" Heartbeat "event to the client, if it is in" pull "mode, the "Heartbeat" and "refresh" events are sent to the client together, notifying the client to send a new request and establish a connection.

Session management between customer servers

The server sends messages on the client.joinWhen a request is sent, a session ID is assigned to the client and sent to the client. Then, the client sends a session IDsubscribeAndlistenRequest. The server maintains a subscribed topic set and event queue for each session.

The event source on the server sends the newly generated events to the event queue of each session (that is, the subscriber) in multicast mode.

Official Website: http://www.pushlets.com/

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.