首页 > 解决方案 > How to connect to Unix Domain Socket on client side service knowing only socket file descriptor

问题描述

My Service A communicates with another Service B on the same host through UNIX Domain Socket (UDS). The only information I have is a value of socket file descriptor with which the Service B is ready to send data through socket to Service A. I use 3rd party library junixsocket to communicate through UDS between services. And my question is how using this library I can connect to the socket on Service A side knowing only the socket file descriptor?

I just found how to connect to socket on Service A side with socketPath:

File socketFile = new File("/path/to/your/socket"); AFUNIXSocket sock = AFUNIXSocket.newInstance(); sock.connect(new AFUNIXSocketAddress(socketFile));

But I need to know how to connect to it with just file descriptor

I’m using openJDK-11, that’s why I have to use 3rd party library for UDS communication

标签: javaunix-socket

解决方案


推荐阅读