WebSocket

WebSocket

"HTML5 WebSocket is a revolutionary new communication feature in the HTML5 specification, which defines a full-duplex communication channel that operates over the Web through a single socket. WebSocket is not just another incremental enhancement of conventional HTTP communications; it represents a major advance for real-time, event-driven web applications. This Refcard includes technical details of the WebSocket protocol, sample API usage, fallbacks for older browsers, and more."1

WebSocket: a standard protocol for creating long-running bi-directional connections between a browser and a server.


W3C WebSocket http://dev.w3.org/html5/websockets

RFC 6455 defines the protocol. http://tools.ietf.org/html/rfc6455

WebSockets allow extremely low latency communication with little overhead.

WebSockets are useful for streaming events in realtime to many listeners.

Example: These listeners can implement realtime dashboards or alerts based on events.

WebSockets are a part of the HTML5 specification.

WebSockets are a part of the Java Servlet 3.1 specification.

JSR 340: Java Servlet 3.1 Specification. http://jcp.org/en/jsr/detail?id=340

JSR 356 is defining a standard API for creating WebSocket applications in the Java EE 7 Platform.

http://jcp.org/en/jsr/detail?id=356

W3C SSE

http://dev.w3.org/html5/eventsource

Reference Implementation (RI)

Tyrus: Web Socket RI for Java http://java.net/projects/tyrus

WebSocket is a layer on top of TCP

  • adds a web origin-based security model for browsers
  • adds an addressing and protocol naming mechanism to support multiple services on one port and multiple host names on one IP address
  • layers a framing mechanism on to of TCP to get back to the IP packet mechanism that TCP is build on, but without length limits
  • includes an additional closing handshake in-band that is designed to work in thee presence of proxies and other intermediaries.

Glassfish3 3.1.2 asadmin set configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.websockes-support-enabled=true

or set via admin console

-server-config > Network Listeners > select listener > HTTP tab > Websockets support

Data Grids

JCache standard api for caches JSR 107 - (Jee7) Note: Coherence supports the API


Frameworks:

  • Atmosphere

"The only Portable WebSocket/Comet Framework supporting Scala, Groovy and Java"

https://github.com/Atmosphere/atmosphere/tree/atmosphere-1.0.x

Blog: http://jfarcand.wordpress.com/

Chat Sample

[Client] https://github.com/Atmosphere/atmosphere/blob/master/samples/chat/src/main/webapp/jquery/application.js#L1

[Server] https://github.com/Atmosphere/atmosphere/blob/master/samples/chat/src/main/java/org/atmosphere/samples/chat/Chat.java#L32

GWT Sample

[Client] https://github.com/Atmosphere/atmosphere-extensions/blob/master/gwt/samples/gwt-chat/src/main/java/org/atmosphere/samples/client/GWTDemo.java#L53

[Server] https://github.com/Atmosphere/atmosphere-extensions/blob/master/gwt/samples/gwt-chat/src/main/java/org/atmosphere/samples/server/ChatHandler.java#L37-L69

References