Contact

jWebSocket Headquarter

Innotrade GmbH

An Vieslapp 29

52134 Herzogenrath

Germany

Publications – Overview

jWebSocket instead of XHR and Comet

06/2010

Google's Chrome 4 is the first browser that supports HTML 5 WebSockets - more to follow. In contrast to XHR and Comet are WebSockets bidirectional and resource-, and perfectly suited for server-to-client streaming (S2C) and client-to-Client Communication (C2C) - for the ticker, chat, online collaboration, or gaming applications. JWebSocket.org on this new technology is available as a GPL open-source library.

Alexander Schulze

jWebSocket is a high-speed Java communications server for HTML5 web using a JavaScript client without any special third party plug- ins. A Java client for desktop applications, for example, appears in Swing in March. The server, a simple. Jar file can run as a standalone service or as well integrated into web applications under Tomcat, JBoss, Jetty or GlassFish will. For the client side, only a single. Js file is required.

It includes the WS-protocol implementation, session management and authentication as well as connectors for JSON, CSV and XML. Additionally, a streaming API, Remote Procedure Calls (RPC) and a plug-in model for your own business logic. For enterprise applications, multiple servers are connected to a cluster.

Benefits of WebSockets

The use of TCP replaces not only the known and Comet from XHR request / response constraint, we remove the HTTP overhead. This causes shorter latency and more bandwidth. While evidence for HTTP streaming two channels that offer real WebSockets Full-duplex on a single TCP socket. WAS A server can therefore manage twice as many simultaneous connections.

On the client offers HTML 5 standard events in order or the assembly and disassembly of a connection to process incoming data packets. Complicated and browser-specific polling or buffering mechanisms omitted. An overview of which browsers support WebSockets, and a WS-based chat application available on jWebSocket.org.

Handshake

As with XHR, the WebSocket client to connect to the server build as well. However, it will exchange a handshake as opposed to HTTP by specification to maintain. For a server with WebSocket initiated by the client instead of http on the new scheme was: / / domain.tld: port / path? arguments the connection. The client sends a header in the form of:

GET HTTP/1.1
Upgrade: WebSocket
Connection: Upgrade
Host: : 
Origin: http:// [: ]

The server sends the following answer:

HTTP/1.1 101 Web Socket Protocol Handshake 
Upgrade: WebSocket 
Connection: Upgrade 
WebSocket-Origin: http://[: ] 
WebSocket-Location: was:// : /

Subsequently, both parties exchange bidirectional over a single socket channel data. The handshake is primarily safety issues, in order to control such as cross-domain requests.

Tokens

Basically, the client and server can now exchange any data packets, jWebSocket provides appropriate protocols for their own low-level classes. Packets, however, hold for both easy to interpret, implement the overlying layer protocol known as tokens. On the server that are Java objects to the outside either JSON, CSV or XML packets. Tokens can be exchanged in both directions, processed and answered. Support for streaming applications jWebSocket so-called one-way token, in which the sender expects no response from the recipient.

First launch and integration into your own applications

After downloading an executable stand . jar for a standalone server as well as the local file system executable demo site provides a - an immediate feeling of success without any Web server or other installations. To jWebSocket the server to operate as a service, provides the Java Service Wrapper from Tanuki Software, a solution for production systems. Likewise, the . jar existing web applications integrated in easily. Many source examples are available on jWebSocket.org.

Expand with Plug-ins

The jWebSocket core represents only provides a basic functionality. To extend this easily, is the implementation of application logic using plug-ins. Even the custom functions are realized by plug-ins. The API is kept simple and limited to three methods on the incoming token in the chain of plug-ins intercepted, can be answered or delegated. So easily have extensive applications are developed in teams, and integrated into an overall solution.

Streaming

While in financial or news tickers, the task is to carry on their own or supplied data streams from the server to different clients, it comes with online collaboration and online games on it, spread quickly to events on different clients to other clients. The jWebSocket server manages this, several streams, register in which the clients.

The streams themselves can be supplied by their own data or external pumps or by the clients, which opens the doors in all directions. In a Time Stream jWebSocket package is included, every second of the current time sent to the registered clients - this example can be tried out on jWebSocket.org online.

Connection Control and Keep-Alive

To unblock ports for new connections, inactive clients will be disconnected after a certain time. For applications where users watch in the first place - such as news - or financial market ticker - jWebSocket offers the client a keep-alive (ping) to the usual session time-out. In the case of network failures, the client can even automatically restore the connection without data loss in subscribers stream.

URL parameters

About the URL, it is possible the client, while connecting the server to forward arguments. Although the format in the WAS protocol does not specify jWebSocket holds here but to the well-known form: w: / / host: port [/ path1 [/ path2]] [? arg1 = [& arg2 = value2]] value1. JWebSocket The client uses this method to select the data format (JSON, CSV or XML) and one individual session timeouts within specified limits. For special requirements, the connection string to be interpreted individually.

Remote Procedure Calls

Because of their quick response behavior offer WebSockets the favored basis for so-called Remote Procedure Calls (RPC). The amount included in jWebSocket-RPC plug-in provides the ability to methods shared Java classes on the server from the client to call and to return the result. On jWebSocket.org is an example of how a MD5 checksum is calculated from a string on the server and returned via RPC.

Alexander Schulze: Founder jWebSocket the project, IT consultant and trainer for specialist. He is a speaker at various conferences and author of several articles and books and serves companies in the database, communications and Web technologies.

Copyright © 2013 Innotrade GmbH. All rights reserved.