Java 中的 UNIX 域套接字

发布于 2024-09-30 19:41:37 字数 408 浏览 1 评论 0原文

我看到这些线程 Java 的 UNIX 套接字实现?http://forums.sun.com/thread.jspa?threadID=713266

第二个链接说Java已经支持UNIX域套接字。如果这是真的,我需要从 Java 实现什么类?

从第一个链接来看,它说Java不支持UNIX Domain Socket。如果您需要 UNIX 域套接字,则必须使用第 3 方库。

那么,是哪一个呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

国际总奸 2024-10-07 19:41:37

您可以使用 junixsocket: https://github.com/kohlschutter/junixsocket

它通过以下方式提供 AF-UNIX 支持一个 JNI 库,利用 Java Socket API。它甚至允许通过 Unix 套接字从 Java (Connector/J) 连接到 MySQL。

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.

晨与橙与城 2024-10-07 19:41:37

如果不使用第 3 方(本机)库,Java 无法创建或访问 Unix 域套接字。上面第二个链接的最后评论提到了这一点。

第一个链接有一些很好的(并且正确的)信息。

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.

固执像三岁 2024-10-07 19:41:37

Netty 从 4.0.26 版本开始也支持它: https://github.com/netty/netty/pull /3344

Netty also supports it since version 4.0.26: https://github.com/netty/netty/pull/3344

橘香 2024-10-07 19:41:37

正如 @Benny 在评论中指出的,JDK 16 通过 java.net.UnixDomainSocketAdress 及相关类。您可以在 JEP-380 阅读更多

内容JEP 的片段:

var unixAddr = UnixDomainSocketAddress.of("/foo/bar.socket");
var Channel2 = SocketChannel.open(unixAddr);

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);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文