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
Pinging web socket experts @Nikita.Savchenko and @Fabian.Haupt.
Also see Fabian's article about web sockets, HTH.
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.
Nikita, he is also asking about cache as websocket CLIENT not as server.
Missed this. I have never seen WS client implementations on COS neither.
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.
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.
Are there any news regarding establishing a websocket connection from COS as a client?
%Net.WebSocket.Client is available and provides WebSocket client.
Great !
Did you try a backport to Caché (18. or so) ?
Please consider upgrading to InterSystems IRIS!
IRIS 2020.1 !!!
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.
A native COS example is available in Open Exchange now.
WebSocket Client Demo in IRIS 2020.1
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