Is there a way to use Unix Domain sockets with Java NIO? I want to use NIO so that I can use Selectors on it in a single thread.
I had a look at junixsocket but it only seems to support normal Sockets not NIO channels that support selectors.
You can use the project jnr-unixsocket,( https://github.com/jnr/jnr-unixsocket ) which is the far most advanced implementation I've seen. It does exactely what you want : nio concepts Selectors, Channels etc
Look @ https://github.com/jnr/jnr-unixsocket/tree/master/src/test/java/jnr/unixsocket/example
I confirm XNIO supports the use of Unix domain sockets, as "local sockets". In addition to release note mention, here are:
But none of XNIO channels implement SelectableChannel so I fear you will not be able to use Selectors.
I propose you post an issue to improve this situation, both in XNIO and also in GNU ClassPath project where LocalSocket.getSocketChannel returns null
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.