# Udp timeout?

**URL:** <https://discourse.julialang.org/t/udp-timeout/9215>\
**Category:** General Usage\
**Created:** [February 20, 2018, 9:01pm UTC](https://discourse.julialang.org/t/udp-timeout/9215 "2018-02-20T21:01:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)\
**Post date:** [February 20, 2018, 9:01pm UTC](https://discourse.julialang.org/t/udp-timeout/9215/1 "2018-02-20T21:01:29Z")

</div>

I want to timeout if I don’t get any messages.

The equivalent of that would be to simply do some sort of wait condition on the channel, and if there was no data ready then timeout.

I thought I had found something to do that in the docs, but now I can’t seem to find it, so if there is such a thing could someone point me to it ?

A couple of things about this code bother me.

One is that I’m putting bytes in the channel one at a time, and I’m thinking there’s a better way to do that.=

The other is that putting a close(sock) at the end of the code causes a core dump.

I’ve seen this mentioned in another post, and there didn’t seem to be any resolution.  
Regardless of whether or not something’s being done incorrectly, a core dump on a mistaken close seems like a serious bug.

Thanks!

```julia
function getdata(address, chan)
    @async begin
         udpsock = UDPSocket()
         bind(udpsock, address, 2000)
         while true
             x = recv(udpsock)
             put!(chan, UInt8(length(x)))
             for byte in x
                 put!(chan, byte)
             end
         end
    end
end

c = Channel{UInt8}(100)

getdata(ip"127.0.0.1", c)

println("Sending")
sock = UDPSocket()

for i=1:10
    println("i=", i)
    send(sock, ip"127.0.0.1", 2000, "$i:Hello World from the UDP")
    n = take!(c)
    x = Array{UInt8,1}()
    for i=1:n
        push!(x, take!(c))
    end
    println(String(x))
end

```

---

<div class="post-metadata">

**Author:** ![y4lu](https://avatars.discourse-cdn.com/v4/letter/y/47e85d/32.png) [@y4lu](https://discourse.julialang.org/u/y4lu)\
**Post date:** [February 21, 2018, 2:45pm UTC](https://discourse.julialang.org/t/udp-timeout/9215/2 "2018-02-21T14:45:00Z")

</div>

Based on `methods(UDPSocket)` and `?sock`  
`sock = UDPSocket(sock.handle, 5 or 6?)` for closing/closed UDP states ?
