# UDPSocket()

**URL:** https://discourse.julialang.org/t/udpsocket/137291
**Category:** General Usage
**Tags:** udp
**Created:** [May 27, 2026, 8:57am UTC](https://discourse.julialang.org/t/udpsocket/137291 "2026-05-27T08:57:42Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)
#### Post date: [May 27, 2026, 8:57am UTC](https://discourse.julialang.org/t/udpsocket/137291/1 "2026-05-27T08:57:42Z")

</div>

I have severe problems to listen to a port on which an UDP-Socket server sends packages.  
I see the packages in `Wireshark` and my Python-Script can see the packages as well.  
But I struggle to achieve the same in Julia.  
Here a short snippet, that does **not** work. The process stucks in line `data, addr = recvfrom(sock)`.

```julia-auto
using Sockets

sock = Sockets.UDPSocket()
Base.bind(sock, ip"0.0.0.0", 59000)
println("Socket bound. Waiting for packet (blocking)...")

addr, data = Sockets.recvfrom(sock) # direct, synchron, no async

println("✅ Received $(length(data)) bytes from $addr")
println(" Data: $(String(copy(data)))")
Base.close(sock)

```

Any ideas?

---

<div class="post-metadata">

### Author: ![KajWiik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kajwiik/32/199_2.png) [@KajWiik](https://discourse.julialang.org/u/KajWiik)
#### Post date: [May 27, 2026, 9:34am UTC](https://discourse.julialang.org/t/udpsocket/137291/2 "2026-05-27T09:34:27Z")

</div>

It works fine for me locally (same host). I sent the test packet with  
`echo -n "hello" | nc -u -w1 127.0.0.1 59000`

Also from remote:  
`echo -n "hello" | nc -u -w1 dell.local 59000`

---

<div class="post-metadata">

### Author: ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)
#### Post date: [May 27, 2026, 1:50pm UTC](https://discourse.julialang.org/t/udpsocket/137291/3 "2026-05-27T13:50:37Z")

</div>

> [@KajWiik](#):
>
> echo -n “hello” | nc -u -w1 dell.local 59000

both commands do not work for me.  
And what would be the purpose?

---

<div class="post-metadata">

### Author: ![KajWiik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kajwiik/32/199_2.png) [@KajWiik](https://discourse.julialang.org/u/KajWiik)
#### Post date: [May 27, 2026, 3:03pm UTC](https://discourse.julialang.org/t/udpsocket/137291/4 "2026-05-27T15:03:08Z")

</div>

This was in Ubuntu, are you using Windows or Mac if `nc` is not available? Someone using them could comment.

---

<div class="post-metadata">

### Author: ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)
#### Post date: [May 27, 2026, 3:09pm UTC](https://discourse.julialang.org/t/udpsocket/137291/5 "2026-05-27T15:09:54Z")

</div>

The following works 🙂 (AI Proton Lumo with my strong choaching 😉 )

```julia-auto
using Sockets

ch = Channel{Tuple{Union{Nothing, Sockets.InetAddr}, Union{Nothing, Vector{UInt8}}}}(1)
udp_sock = Sockets.UDPSocket()
Base.bind(udp_sock, ip"0.0.0.0", 59000; reuseaddr=true)

# Voll qualifiziert: Base.Threads.@spawn
recv_task = Base.Threads.@spawn begin
    try
        addr, data = recvfrom(udp_sock)
        put!(ch, (addr, data))
    catch
        put!(ch, (nothing, nothing))
    end
end
println(ch)
addr, data = take!(ch)
close(ch)
println(data)

Base.close(udp_sock)
@info "done"

```

P.S.:  
There exist an alternative to encapsulate the _troublemaker_: `addr, data = recvfrom(udp_sock)`:

```julia-auto
recv_task = Base.Threads.@async while running[]
# ...
end

```

Any arguments to decide which of them is the best, to enable a sound handling of `InterruptException`?
