Piping stdout to websockets

I was thinking of ways to stream pipes through ipc, and came across this which redirects stdin/out through websockets. Maybe some of you find it interesting.

https://github.com/joewalnes/websocketd

$ ./websocketd --port 8080 curl “http://stream-sandbox.oanda.com/v1/prices?accountId=12345&instruments=AUD_CAD%2CAUD_CHF%2CGBP_USD%2CUSD_EUR” -N  

Fri, 10 Oct 2014 21:07:02 +0200 | INFO   | server     |  | Serving using application   : /usr/bin/curl http://stream-sandbox.oanda.com/v1/prices?accountId=12345&instruments=AUD_CAD%2CAUD_CHF%2CGBP_USD%2CUSD_EUR -N

Fri, 10 Oct 2014 21:07:02 +0200 | INFO   | server     |  | Starting WebSocket server   : ws://:8080/

Fri, 10 Oct 2014 21:07:08 +0200 | ACCESS | session    | url:‘http://host:port/’ id:‘1412968028000414119’ remote:‘localhost’ command:‘/usr/bin/curl’ origin:‘file://’ | CONNECT

Fri, 10 Oct 2014 21:07:08 +0200 | ERROR  | stderr     | url:‘http://host:port/’ id:‘1412968028000414119’ remote:‘localhost’ command:‘/usr/bin/curl’ origin:‘file://’ pid:‘35749’ |   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

Fri, 10 Oct 2014 21:07:08 +0200 | ERROR  | stderr     | url:‘http://host:port/’ id:‘1412968028000414119’ remote:‘localhost’ command:‘/usr/bin/curl’ origin:‘file://’ pid:‘35749’ |                                  Dload  Upload   Total   Spent    Left  Speed

Fri, 10 Oct 2014 21:07:12 +0200 | ACCESS | session    | url:‘http://host:port/’ id:‘1412968028000414119’ remote:‘localhost’ command:‘/usr/bin/curl’ origin:‘file://’ pid:‘35749’ | DISCONNECT

and then in kdb+

q).z.ws:{0N!x;} / just print incoming

q)r:(`$“:ws://127.0.0.1:8080”)“GET / HTTP/1.1\r\nHost: host:port\r\n\r\n”

q) / updates printed below

“{"tick":{"instrument":"AUD_CAD","time":"2014-10-10T19:07:40.359506Z","bid":0.93824,"ask":0.93875}}”

“{"tick":{"instrument":"AUD_CHF","time":"2014-10-10T19:07:38.362939Z","bid":0.97566,"ask":0.97603}}”

“{"tick":{"instrument":"GBP_USD","time":"2014-10-10T19:07:37.750485Z","bid":1.4758,"ask":1.47598}}”

“{"tick":{"instrument":"USD_EUR","time":"2014-10-10T19:07:39.219876Z","bid":0.79621,"ask":0.79627}}”

“{"tick":{"instrument":"AUD_CAD","time":"2014-10-10T19:07:41.062111Z","bid":0.9383,"ask":0.93881}}”

“{"tick":{"instrument":"USD_EUR","time":"2014-10-10T19:07:41.660565Z","bid":0.79624,"ask":0.7963}}”

“{"tick":{"instrument":"AUD_CHF","time":"2014-10-10T19:07:41.901723Z","bid":0.9757,"ask":0.97607}}”

“{"tick":{"instrument":"USD_EUR","time":"2014-10-10T19:07:41.964353Z","bid":0.79626,"ask":0.79632}}”

very interesting idea!
is current free 32-bit version supporting websocket client feature?

yes

Can we connect to KDB(secured by password) through websockets?

As in the following c.js section of article wslogin page, there is a login button, but i am not sure if it is used for login in kdb. It though demonstrates serialize/deserialize.

http://code.kx.com/wiki/Cookbook/Websocket

That example is indeed misleading - it’s relying on a custom authentication via submission to .z.ws.

A websocket connection is an upgrade of an http connection; hence the authentication is part of the http protocol (basic authentication, as comes into force when using the -u/U cmd line option of kdb+). Chrome currently has some issues with this, although firefox is fine. The issue appears to be fixed in the latest release of Chrome ‘Canary’.

Thanks Charles. Authentication works fine in firefox.