”;
KDB+ allows one process to communicate with another process through interprocess communication. Kdb+ processes can connect to any other kdb+ on the same computer, the same network, or even remotely. We just need to specify the port and then the clients can talk to that port. Any q process can communicate with any other q process as long as it is accessible on the network and is listening for connections.
-
a server process listens for connections and processes any requests
-
a client process initiates the connection and sends commands to be executed
Client and server can be on the same machine or on different machines. A process can be both a client and a server.
A communication can be,
-
Synchronous (wait for a result to be returned)
-
Asynchronous (no wait and no result returned)
Initialize Server
A q server is initialized by specifying the port to listen on,
q –p 5001 / command line p 5001 / session command
Communication Handle
A communication handle is a symbol that starts with “:” and has the form −
`:[server]:port-number
Example
`::5001 / server and client on same machine `:jack:5001 / server on machine jack `:192.168.0.156 / server on specific IP address `:www.myfx.com:5001 / server at www.myfx.com
To start the connection, we use the function “hopen” which returns an integer connection handle. This handle is used for all subsequent client requests. For example −
q)h:hopen `::5001 q)h"til 5" 0 1 2 3 4 q)hclose h
Synchronous and Asynchronous Messages
Once we have a handle, we can send a message either synchronously or asynchronously.
Synchronous Message − Once a message is sent, it waits on and returns the result. Its format is as follows −
handle “message”
Asynchronous Message − After sending a message, start processing the next statement immediately without having to wait and return a result. Its format is as follows −
neg[handle] “message”
Messages that require a response, for example function calls or select statements, will normally use the synchronous form; while messages that need not return an output, for example inserting updates to a table, will be asynchronous.
”;