Comt4j message pushing instance

Source: Internet
Author: User

1.1 Comt4j1.1.1 introduction Comet4J (Comet for Java) is a server push framework purely based on AJAX (XMLHTTPRequest). messages are transmitted in JSON format, three working modes are available: Long polling, long connection, and automatic selection. Feature: pushes message broadcasts. · Push targeted messages. · Various events that can be handled before connection, online, offline, offline, and message sending are provided. · Message caching mechanism ensures that messages are not lost in long polling mode. · The client is normally offline, and the server can immediately perceive it. · The client stops working abnormally. The server can regularly check and detect exceptions. · By registering a channel application, developers can expand the framework functions to implement their own applications. Framework features: independent and small, not dependent on third-party packages. · Tightly integrated with applications without independent applications or servers. · The Session-independent Connection Mechanism provides developers with maximum functional controllability. · Event-oriented programming. Both the client and server are event-driven development models, providing a sound scalability mechanism. · All performance parameters can be configured. · Supports multiple mainstream browsers and Air application environments. Server support: Tomcat 6 and tomcat 7 browsers that support XMLHTTPRequest objects support long polling mode, but not necessarily long connections. Browser/platform version long polling persistent connection Internet assumer6, 9 √ XFireFox3.0 + (unknown version) √ Chrome7.0 + (unknown Version) √ Safari5 + (unknown version) √ Opera11.10 + (unknown version) √ XAir1.5 + (unknown version) √ IOS (Iphone/Ipad) 3.1 + (unknown version) √ Android not tested unknown BlackBerry not tested unknown comparison: Pushlet instance parsing and Servlet3.0 server push technology 1.1.2 server package org. comet4j. demo. helloworld; import javax. servlet. servletContextEvent; import javax. servlet. servletContextListener; import org. comet4j. core. cometContext; import org. comet4j. core. cometEngine; public class HelloWorld implements ServletContextListener {private static final String CHANNEL = "hello"; public void contextInitialized (ServletContextEvent arg0) {CometContext cc = CometContext. getInstance (); cc. registChannel (CHANNEL); Thread helloAppModule = new Thread (new HelloAppModule (), "Sender App Module"); helloAppModule. setDaemon (true); helloAppModule. start ();} class HelloAppModule implements Runnable {public void run () {while (true) {try {Thread. sleep (1000);} catch (Exception ex) {ex. printStackTrace ();} CometEngine engine = CometContext. getInstance (). getEngine (); // push the remaining memory size of the current server. sendToAll (CHANNEL, Runtime. getRuntime (). freeMemory ()/1024) ;}} public void contextDestroyed (ServletContextEvent arg0) {}} 1.1.3 client

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.