comet is a server "push" technology, an implementation, apache-tomcat comet provided support.
Here's what comet works:
Comet server implementation, need to inherit HttpServlet class that implements org.apache.catalina.CometProcessor interface, the server receives a client's request will be called when the event CometProcessor interface method, the object passed to a org.apache.catalina.CometEvent event ( .) CometEvent has four states: CometEvent.EventType.BEGIN, CometEvent.EventType.ERROR, CometEvent.EventType.END, CometEvent.EventType.READ. According to the status of the request to the server to the client to send the appropriate data.
Principle is probably the case, need a concrete implementation to continuously check the message MessageSender whether there is data in the container, there is immediately sent, not to wait; a connectorCleaner to constantly check out the client's connection, if the break-out open, such as the client re-sent a long connection.
To achieve the client's comet, due to the type and version of browser inconsistencies, so the client needs to achieve two different comet, one is the iframe long connection, one is a long stream connection. Iframe for kernel-based browsers ie, the kernel does not support the stream ie long connection, so long connection with the iframe solution. Client request data to the server, the server returns a page with a hidden iframe, the iframe from time to time to send data requests to the server to maintain a long connection, known as the "heartbeat." Stream is the realization of firefox's comet, stream support the connection status of the inquiry, that is, as you can inquire as CometEvent state of the connection, and according to the state to do different operations. Stream long connection will automatically connect to the server without a browser, like ie the kernel that need to refresh iframe to re-establish the connection.
Apache-tomcat on the comet's support, the need to modify the configuration of server.xml, add:
<Connector ConnectionTimeout="20000" port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" redirectPort="8443"/>
At this point the comet can be achieved