xockets.io ...last few enhancements

Datetime:2016-08-22 22:29:16         Topic: WebSocket          Share        Original >>
Here to See The Original Article!!!


The purpose of this post is to cover all the enhancements that have been added to the xockets.io xpages websocket plugin since version 2.0.2.  A good number of enhancements have been added, and up until now I've been a bit lazy when it comes to blogging about it.  This post will cover the following:

  • Addition of scriptable event observers (covers onOpen, onMessage, onClose, onError)
  • Multiple websocket connections per user based on URI  
  • Multiple targets in a SocketMessage
  • Send a collection of messages with one call


Event Observers:    

Event observers are scripts that fire after the main events of the xockets.io server (e.g. onOpen, onMessage, onClose, onError).  Unlike the Rhino client based event listeners, these event observer scripts fire against ALL connected client events.  Because these scripts fire for every event generated by all the connected clients it is very important to write high performance code so the script doesn't tie up the executing thread for too long.  A sample script that logs all the events is below, along with a link to a simple xockets logger application.  Using event observe rs is a two step process, build the n register the script.

1)  Build your event observer script using the XPages SSJS design element .  Be sure your methods are named onOpen, onClose, onMessage, or onError , and that they accept the c orrect number of parameters (see sample scr ipt ).

2) Call the websocketBean.add EventObserver meth od directly or register via console command


If a change is made to an event observer, reload the script using the command line call (tell http osgi xockets reload-scripts)

Multiple websocket connections per user based on URI :

This enhancement allows for a single user session to have multiple websocket connections open across multiple pages / ap plications on the same server .

Multiple targets in a SocketMessage

This enhancement provid es a way to send the same message to multiple peo ple in a single send o peration as opposed to sending a message to each websocket connection individually .  Should increase performance and bandwidth by reducing the total payload across the wire (see below sample):

Send a collection of messages with one call  

T his enhancement makes it easy to send batches / collections of messages to one or more peo ple in one call across the wire.  Note, the batch message will be interpreted as a single message when validating size Handy if storing messages when disconnected , and batch uploading them periodically.


Put your ads here, just $200 per month.