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

**URL:** <https://erlangforums.com/t/how-to-check-if-unix-domain-socket-client-is-listening-on-the-other-side/3859>\
**Category:** Questions / Help\
**Tags:** sockets, gen\_tcp, inet\
**Created:** [July 24, 2024, 10:15pm UTC](https://erlangforums.com/t/how-to-check-if-unix-domain-socket-client-is-listening-on-the-other-side/3859 "2024-07-24T22:15:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![codeadict](https://erlangforums.com/user_avatar/erlangforums.com/codeadict/32/1763_2.png) [@codeadict](https://erlangforums.com/u/codeadict)\
**Post date:** [July 24, 2024, 10:15pm UTC](https://erlangforums.com/t/how-to-check-if-unix-domain-socket-client-is-listening-on-the-other-side/3859/1 "2024-07-24T22:15:35Z")

</div>

Hi all,

I have a TCP client connected to a UNIX domain socket with gen\_tcp with:

```erlang
{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](http://erlang.org/doc/man/erlang.html#port_info-1) helps with a regular TCP socket but not with Unix Domain Sockets.

Thanks! 😃

---

<div class="post-metadata">

**Author:** ![raimo](https://erlangforums.com/user_avatar/erlangforums.com/raimo/32/867_2.png) [@raimo](https://erlangforums.com/u/raimo)\
**Post date:** [July 25, 2024, 7:50am UTC](https://erlangforums.com/t/how-to-check-if-unix-domain-socket-client-is-listening-on-the-other-side/3859/2 "2024-07-25T07:50:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![codeadict](https://erlangforums.com/user_avatar/erlangforums.com/codeadict/32/1763_2.png) [@codeadict](https://erlangforums.com/u/codeadict)\
**Post date:** [July 25, 2024, 3:03pm UTC](https://erlangforums.com/t/how-to-check-if-unix-domain-socket-client-is-listening-on-the-other-side/3859/3 "2024-07-25T15:03:41Z")

</div>

Thanks a lot @raimo, that worked perfectly
