Hi,
Is there a specific reason for server>client?
I have tried to cover both below, hopefully it is at least a starter for you and helps..
q)/server process
q)p 50001
q)/ heartbeat table to log hbs
q)heartbeat:([host:`$();port:`long$()];hdl:`int$();lastPing:`timestamp$();pings:`long$())
q)/function to log hearbeat on server
q)registerHeartBeat:{[hst;prt] `heartbeat upsert (hst;prt;.z.w;.z.p;)1+0^first exec pings from heartbeat where host=hst,port=prt }
q)/client process
q)p 50000
q)/ hdl to server
q).R.Server:hopen `::50001
q)/ send heartbeat from client to server
q)sendHeartBeat:{ .R.Server (`registerHeartBeat;.z.h;system "p")}
q)/ call send a heart beat from client to server
q)sendHeartBeat[] / this could be on a timer
`heartbeat
// check on the server
q)heartbeat
host port | hdl lastPing pings
---------------------| ---------------------------------------
desktop 50000| 9 2022.03.04D12:31:48.583133000 1
/ initiating from server side
/ have each client process register with the server on startup (for this I have just manually called sendHeartBeat from client)
/ to add hdls to heartbeat table
q)/ callback type idea to initiate a registerHeartBeat call
q)reportToServer:{ .z.w (`registerHeartBeat;.z.h;system "p")}
q)/ this function on server would request a heart beat from each hdl in the heartbeat table
q)getHeartBeatFromServer:{ (exec distinct hdl from heartbeat)@:(reportToServer;`)}
q)/ call above function, which could be on a timer
q)getHeartBeatFromServer[]
,`heartbeat
q)heartbeat
host port | hdl lastPing pings
---------------------| ---------------------------------------
desktop 50000| 9 2022.03.04D12:33:28.583133000 2
Thanks