IPC: Connecting
Kdb+ uses tcp/ip connection to talk between two kdb+ processes or when using http browser
All messages in kdb+ connection goes via message handler functions
-
to declare port number inside a q process we use
/p [port_number]
, we can also assign port number when starting the process using-p [port_number]
-
when inside a process we can use
\p
to see the port number, by default if port number is not declared it0i
- let's create 2 q processes:
- server - one which is serving queries
-
client - one which is making queries
-
we can open a connection from client to server using function
hopen
- we can also see which socket this handle is assigned to by checking value of
h
- we can use another version of hopen command by specifyign host and port number -
hopen ``:host:port
- we can see all the handles open on client process by checking dictionary
.z.W
- to close a connection we use function
hclose
- we can also give handle number as an argument to
hclose
function to close a handle - handle number can be checked from.z.W
command
Message Handler Functions
- we can reset any of the message handler function to their original definition by using
\x function_name
or\x .z.pw
.z.pw
- used to check password of user while opening connection
- arguments to
.z.pw
function are username and password - can be reset to default using
\x .z.pw
.z.po
- this is executed whenever a handle is opened and after
.z.pw
has executed successfully - we can print details of just opened handle in this function, like: ip address, username, date time and handle number
- argument passed to function
.z.po
is handle number .z.a
- show ip address.z.p
- current timestamp.z.u
- user opening handle
// server
q).z.po:{[x] show(.z.a;.z.p;.z.u;x)}
{[x] show(.z.a;.z.p;.z.u;x)}
q)2130706433i
2022.02.21D03:38:51.578467000
`abc
10i
.z.pc
- we can use
.z.pc
to be executed whenever a handle is closed to server
Timeout
- we can also define timeout in millisecods when opening a handle
Restricting user access on start-up
- we can define username and password combination in a file and specify it using
-u filepath
when strating q session - Only username password combination in the file will be allowed when opening handle