KxSystems / javakdb

Using Java with kdb+
https://code.kx.com/q/interfaces
Apache License 2.0
52 stars 45 forks source link

UDS support #72

Closed sshanks-kx closed 8 months ago

sshanks-kx commented 8 months ago

java16 added ads e.g. https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/net/UnixDomainSocketAddress.html

sshanks-kx commented 8 months ago

uds doesnt appear to support Socket/ServerSocket (used in c.java) - rather uses ServerSocketChannel / SocketChannel

e.g. using ServerSocketChannel to get a ServerSocket (or vice versa) throws exceptions

java.net.UnixDomainSocketAddress address = java.net.UnixDomainSocketAddress.of(socketFile);
java.nio.channels.ServerSocketChannel serverChannel = java.nio.channels.ServerSocketChannel.open(java.net.StandardProtocolFamily.UNIX);
ServerSocket s=new ServerSocket();
s.bind(address);

... bind checks for InetSocketAddress, IllegalArgumentException("Unsupported address type")

java.nio.file.Path socketFile = FileSystems.getDefault().getPath("/tmp/", "kx.5010"); 
java.nio.file.Files.deleteIfExists(socketFile);
java.net.UnixDomainSocketAddress address = java.net.UnixDomainSocketAddress.of(socketFile);
java.nio.channels.ServerSocketChannel serverChannel = java.nio.channels.ServerSocketChannel.open(java.net.StandardProtocolFamily.UNIX);
serverChannel.bind(address);
serverChannel.socket();

... socket does 'if (isNetSocket()) {' .... throw new UnsupportedOperationException("Not supported");

sshanks-kx commented 8 months ago

Ability to use UDS (unix domain sockets) between java and kdb+. Requires java version 16 or greater, OS support & client/server residing on same machine. Java reference here

example of client connection when kdb+ listening on 5010

c=new c("/tmp/kx.5010",System.getProperty("user.name")+":mypassword");

example of creating server when kdb+ connecting with h:hopen`:unix://1234

java.net.UnixDomainSocketAddress address = java.net.UnixDomainSocketAddress.of("/tmp/kx.1234");
ServerSocketChannel serverChannel = ServerSocketChannel.open(java.net.StandardProtocolFamily.UNIX);
serverChannel.bind(address);
// pass serverChannel to c contructor to wait til new client connection occurs