Introduction

In ZK 8.5, there is a new session, where a WebSocket-based update engine is introduced to handle requests if the browser is supported.

The advantage of WebSocket (over AJAX), is once the connection has been established, all future messages are passed over the socket rather than new HTTP request/response calls. The ping and pong messages will be smooth and also save traffic!

We support not only WebSocket-based Update Engine, but also a WebSocket-based server push. This reduces the count of http connections when there is a huge amount of updates.

WebSocket Demo

In the first clip, we can see when the ajax-based ZK update engine is on, numerous requests will be established. While in the second clip, with websocket based ZK update engine, there is only one connection established; even if we enable server push, less HTTP overhead.

Required Configuration

Versions:

  • ZK: 8.5.0.FL.20170725-Eval or later
  • Browser: Internet Explorer 10+, Edge, Firefox, Chrome, Safari, iOS Safari, Android Browser, Opera

zk.xml

<!-- required -->
<listener>
	<listener-class>org.zkoss.zkmax.au.websocket.WebSocketWebAppInit</listener-class>
</listener>

<!-- optional -->
<library-property>
	<name>org.zkoss.zkmax.au.websocket.WebSocketEndPoint.urlPattern</name>
	<value>/myappws/</value>
</library-property>
    • Line 2 to 4: It is required to add a configuration org.zkoss.zkmax.au.websocket.WebSocketWebAppInit to enable the WebSocket connection.
    • Line 6 to 9: Map the url pattern for WebSocket connection; if this library property is not configured, /zkwm will be used by default.

Be noted that WebSocketServerPush will be the selected server push class if the WebSocket connection is on, even though other server push class is configured in zk.xml.

Downloads

The whole demo project can be found on Github project.

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

One Response to “ZK 8.5 Preview: Built in WebSocket Communication is Now Provided”

  1. Costas Yiannoulis says:

    I can’t wait to see this feature!

Leave a Reply