2023.05.05 02:02 AM
Hi,
I try to subscribe table in KDB server from a javascript client using websocket and receive message from KDB server. The websocket connection is good, and I can get the handle (assume the handle is 10). However, when I try to publish data to javascript client using -25!(enlist 10; msg), it throws an error: 10 is not an ipc handle. I have checked the connection is still alive, and I can publish data to client using neg[10] msg. So is there any constraints on async broadcast(-25!)? Can someone help me with this? Thanks a lot!
2023.05.05 02:30 AM
-25! is for use with IPC handles only. Not websocket handles.
The reason is for IPC handles there is a serialization step and here -25! is efficient in allowing this to only be run once for many handles.
For websocket handles data is sent directly without any serialization step, -25! would offer no benefit here.
q){([]h)!-38!h:.z.H}[]
h | p f
---| ---
612| w t
580| q t
q)-25!(enlist 612i;"test")
'612 is not an ipc handle
[0] -25!(enlist 612i;"test")
^
q)-25!(enlist 580i;"test")
For websockets if there is a large operation like converting a table to JSON you can control this being done once and then sent to multiple websockets:
neg[webSockethandles]@\:.j.j bigTable
Wrapping the same in a helper:
wsBroadcast:{[handles;data] neg[(),handles]@\:data}
wsBroadcast[myWebsocketHandles] .j.j bigTable
2023.05.05 02:30 AM
-25! is for use with IPC handles only. Not websocket handles.
The reason is for IPC handles there is a serialization step and here -25! is efficient in allowing this to only be run once for many handles.
For websocket handles data is sent directly without any serialization step, -25! would offer no benefit here.
q){([]h)!-38!h:.z.H}[]
h | p f
---| ---
612| w t
580| q t
q)-25!(enlist 612i;"test")
'612 is not an ipc handle
[0] -25!(enlist 612i;"test")
^
q)-25!(enlist 580i;"test")
For websockets if there is a large operation like converting a table to JSON you can control this being done once and then sent to multiple websockets:
neg[webSockethandles]@\:.j.j bigTable
Wrapping the same in a helper:
wsBroadcast:{[handles;data] neg[(),handles]@\:data}
wsBroadcast[myWebsocketHandles] .j.j bigTable
2023.05.08 12:08 AM
Thanks a lot rocuinneagain! I assumed websocket handles were also IPC handles. -38! gives me the answer. Again very appreciate for your detailed reply😀
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.