Robert Cemper · Feb 8, 2019 2m read

Client for WebSockets based on Node.js

WebSockets as a communication technology wins increasing importance.
In the SAMPLES namespace, you find a nice example for running a WebSocket Server.
There is also a useful example for a Browser Client. JavaScript does most of the work. 

My point is:
How to consume the output of a WebSocket Server in your application?

<--break->You may take the engineering approach and use the available tools and classes to handle
everything around protocol switching, encoding, encryption, .... 
It is great if you are able to achieve this and if you are willing to invest the required time and find a sponsor to support it.

On the other hand, this is re-inventing the wheel. This works already in almost every browser.
e. g JavaScript has excellent and verified libraries to support what you need.

And there is the engine to run it without a browser: Node.js
And Caché, IRIS, Ensemble have meanwhile a well-established interface module ready.

So I took a closer look after managing to get the correct versions together.

Once the WsockDemo.js was assembled and tested you launch it over CPIPE or $ZF(....)
You provide control information from the server and get back the result to the server.

If you are used to JavaScript there are no big surprises. The major difference to accept and
understand is that yo operate in an almost total asynchronous environment and callback
methods and their interaction are probably the most important difference to traditional

I have placed the example here with more docs as an invitation to break out
(for most developers) of your traditional environment and find something new and useful.

 I have to admit that this was my first exercise into Node.js and I'm far from taking the best
and most advanced solution. But the result in relation to the effort was convincing.  


 This is a coding example working on Cache 2018.1.3  
 It will not be kept in synch with new versions      
 It is also NOT serviced by InterSystems Support !
0 0 1 354
Log in or sign up to continue


This example from Caché was adapted to use IRIS Native API for Node.js
It is now an independent service and not bound to the IRIS server.
Control happens  using ^ZSocketRun
//       -1 => stop server and exit
//          0 => wait for action
//        1 => sent to echo server
//           ^ZSocketRun(0)= echo server => "wss://"

Check the related application on InterSystems Open Exchange.
or on GitHub


 This is a coding example working on IRIS 2020.1  
 It will not be kept in synch with new versions      
 It is also NOT serviced by InterSystems Support !