Question
· 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

Discussion (14)2
Log in or sign up to continue

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.

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.

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