# How to get port number of ephemeral port?

**URL:** <https://discourse.julialang.org/t/how-to-get-port-number-of-ephemeral-port/19954>\
**Category:** General Usage\
**Created:** [January 23, 2019, 12:25am UTC](https://discourse.julialang.org/t/how-to-get-port-number-of-ephemeral-port/19954 "2019-01-23T00:25:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [January 23, 2019, 12:25am UTC](https://discourse.julialang.org/t/how-to-get-port-number-of-ephemeral-port/19954/1 "2019-01-23T00:25:15Z")

</div>

If I do,

```julia
using Sockets
l = listen(IPv4("127.0.0.1"),0)

```

then I’ve created a socket to listen on ephemeral port. Is there a way from Julia to get the port number so I know where to connect to from the other process? Thanks.

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [January 23, 2019, 12:28am UTC](https://discourse.julialang.org/t/how-to-get-port-number-of-ephemeral-port/19954/2 "2019-01-23T00:28:48Z")

</div>

Ah `methodswith(typeof(l))` gave me a hint where to look and looks like,

```julia
convert(Int,getsockname(l)[2])

```

is my answer.
