Reputation: 1000
I see these threads UNIX socket implementation for Java? and http://forums.sun.com/thread.jspa?threadID=713266.
The second link says that Java already supports UNIX Domain Socket. If that's true what class do I need to implement from Java?.
From the first link, it says that Java does not support UNIX Domain Socket. If you need UNIX Domain Socket you must use a 3rd-party library.
So, which is it?
Upvotes: 19
Views: 35374
Reputation: 27252
As noted by @Benny in a comment, JDK 16 comes with built-in support for unix domain sockets via java.net.UnixDomainSocketAdress and related classes. You can read more at JEP-380
Here's a snippit from the JEP:
var unixAddr = UnixDomainSocketAddress.of("/foo/bar.socket");
var channel2 = SocketChannel.open(unixAddr);
Upvotes: 5
Reputation: 3106
You could use junixsocket: https://github.com/kohlschutter/junixsocket
It provides AF-UNIX support via a JNI library, utilizing the Java Socket API. It even allows connecting to MySQL from Java (Connector/J) via Unix sockets.
Upvotes: 24
Reputation: 1153
Netty also supports it since version 4.0.26: https://github.com/netty/netty/pull/3344
Upvotes: 8
Reputation: 247
Java cannot create or access Unix Domain Sockets without using a 3rd party (native) library. The last comment on the second link above mentions this.
The first link has some good (and correct) information on it.
Upvotes: 17