How to check if unix domain socket client is listening on the other side

Hi all,

I have a TCP client connected to a UNIX domain socket with gen_tcp with:

{ok, port} = gen_tcp:connect({local, "/tmp/cool.sock"}, 0, [{active, false}, {packet, raw}])

If I kill the OS process that serves in /tmp/cool.sock, Iā€™d like to check if port above is open.
Is there any way to check if the socket is open without having to send a message with gen_tcp:send/2?

erlang:port_info/1 helps with a regular TCP socket but not with Unix Domain Sockets.

Thanks! :smiley:

Does inet:peername(Socket) work in this case?

Thanks a lot @raimo, that worked perfectly

1 Like