Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Java NIO with Unix Domain sockets in non-blocking mode with selectors

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.

like image 533
jbx Avatar asked Jan 08 '12 23:01

jbx


2 Answers

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

like image 108
taharqa Avatar answered Oct 21 '22 21:10

taharqa


JDK 16 has built-in support for Unix Domain Sockets. Here's an example from Oracle about using it with NIO

like image 26
Paul Rubel Avatar answered Oct 21 '22 20:10

Paul Rubel