Written by

Owner at NiPaRpbotica
Question Nigel Salm · May 12, 2017

Web Sockets

Hi

I am working on a project that will interact with some software called ROS (Robot Operating System). One of the development challenges we have is as follows:

ROS uses web sockets... So one connect with ws://localhost:9090 to the web socket server.  It starts off as http, but then "upgrades" to web socket.  It then keeps open this "tunnel" for bi-directional communication..

I need something like a HTTP Outbound adapter, but the Web Socket version of it...

Does anyone have any experience in this area?

Nigel

Comments

Nikita Savchenko · May 18, 2017

Hi Nigel!

I have been using %CSP.WebSocket class for my WebTerminal project. All you need to handle WebSocket connections is in this class. By mixing globals and/or interprocess communication you can achieve pretty much any result you need. There are plenty of resources in the Internet to get started with InterSystems WebSockets, but if you have any particular questions (which is not obvious from the post content), feel free to ask.

P.S. Oops, posted answer instead of comment.

0
Fabian Haupt  May 18, 2017 to Nikita Savchenko

Nikita, he is also asking about cache as websocket CLIENT not as server.

0
Nikita Savchenko  May 18, 2017 to Fabian Haupt

Missed this. I have never seen WS client implementations on COS neither.

0
Fabian Haupt · May 18, 2017

I am not aware of any WS client implementation in COS. Keep in mind that WS would mean a continuous connection, which doesn't really fit with the Operations model for Ensemble.

0
Sean Connelly · May 18, 2017

The Ensemble operation would definitely need a custom adapter written.

Probably wouldn't be that hard, just a bit time consuming getting all of the message frames working over TCP and handling fringe issues such as stale buffer data.

The only nag is that implementing this via one operation would be an anti pattern. Unsolicited ROS messages should really be entering Ensemble via a service.

However, there is a quick win that would solve this.

Create a small node process that would multiplex ROS web socket messages between an inbound HTTP service and an outbound HTTP operation.  ROS will think its talking to a socket client whilst Ensemble will thinks its talking to a pub sub over HTTP. Importantly you would get a bi-direction flow of messages in and out of Ensemble in the right directions.

Node has the battle tested libs to translate between the two. At tops probably 100 lines of node glue code to get this working. Leveraging on Ensembles standard HTTP adapters means this should all be stable out of the box.

0
Mathew Lambert · Mar 30, 2020

Are there any news regarding establishing a websocket connection from COS as a client?

0
Robert Cemper  Mar 30, 2020 to Eduard Lebedyuk

Great !   
Did you try a backport to Caché  (18. or so) ?

0
Eduard Lebedyuk  Mar 30, 2020 to Robert Cemper

Please consider upgrading to InterSystems IRIS!

0
Robert Cemper  Apr 1, 2020 to Eduard Lebedyuk

Ok It works in IRIS 2020.1    (e.g against /csp/samples/Web.SocketTest.cls)

The attempt of a backport failed for IRIS 2019.1 and Cache2018.1.3
There seem to be more serious changes than just the client code itself.

0
Robert Cemper · Mar 30, 2020

Hi Nigel,
About a year ago a faced a similar problem and found 2 possible workarounds.

Instead of writing a WS client a delegated it out to JavaScript.
#1)  Using CSP
#2) my preferred one with node.js
Both examples are available on OpenExchange 

Client for WebSockets based on CSP

Client for WebSockets based on Node.js

as Websockets ar so natural to JavaScript the result is no rocket science.

Stay healthy 

0