Brief Review of WebSocket and Comet Frameworks in Java

16 October 2013
By Sergey Remizov, Senior Developer

Intro

Web applications become more and more interactive and dynamic. In some cases regular request-response model is not the best solution, e.g. if the application displays frequently changed data then it needs to hit server for data updates with very short intervals. As result such approach imposes substantial load on network by creating numerous requests to check for updates. WebSocket and Comet protocols are designed to resolve this issue. WebSocket is full duplex protocol and a part of HTML5. Comet is an umbrella term that covers several techniques and approaches that allow a server to send data and notifications to a browser.

Key use cases where WebSocket/Comet might be useful are real-time trading apps, browser games, instant messaging and other applications relying on frequent data updates.

CometD

CometD is one of the most mature Comet frameworks. It has Java client and server API, provides dojo and jquery libraries for easier client side integration. The framework architecture is concise and extensible. The project’s web site has good documentation and a number of examples. The framework provides authentication handling and supports clusterization via 3rd party library. Development of the project is not very active, but new versions are released few times a year.

Atmosphere

In contrast to CometD Atmosphere’s community is very active on Github, new versions are released quite often. Atmosphere’s documentation contains a lot of information and examples. However, some examples use GET/POST annotation from JAX-RS for endpoint mapping which looks quite strange in terms of channel/topic paradigm of WebSocket/Comet and can confuse developers. The framework has extensions for Spring, Wicket, GWT, JSF, Netty and supports a bunch of JS extensions. It also supports JVM languages Scala and Groovy.

Diffusion

The only proprietary framework in this review left mixed feeling. In addition to WebSocket protocol this framework can also operate over proprietary protocol. It has vast number of client libraries including iOS, Android and Flex/Flash. Diffusion has architecture which is rather different from what typical java web based application has. Thanks to proprietary network framework and standalone application container this framework demonstrates very good performance. However, the price of high performance are limitations on deployment options, as Diffusion application can’t be deployed to standard application containers like Tomcat, Jetty, Jboss. This also makes deployment in cloud environment difficult. The framework provides documentation which mostly covers trivial use cases.

Java EE7

Java EE7 and its reference implementation GlassFish 4 comes with built-in support of websockets both on server and client. API is simple, convenient and extensible. Obvious advantage of this choice is solid platform which doesn’t need any external libraries. It could be the right choice if the project is built around Java EE/ WebSocket and doesn’t need to support old browsers and compatibility with Comet.

DIY

The last way to implement server side notification system is to build your own framework. This is not as difficult as it sounds, since latest versions of Jetty and Tomcat have built-in support for asynchronous request processing. In addition to this, Netty framework can be used for deployments on older application servers. This is the longest path but this way you can build a solution which perfectly meets your needs.

Summary

Java world enjoys a variety of Сomet protocol implementations. If you need full support of WebSocket/Comet transport then CometD and Atmosphere frameworks look as the most appropriate choice. CometD is more stable and mature while Atmosphere supports many extensions and frameworks. If you use Java EE 7 application server and old browsers support is not essential then built-in WebSocket library is good enough.

Tags: , ,


Add Comment

Name Mail Website Comment