Receiving UDP packages

Hello,
I am trying to receive UDP packages, containing ASCII data.

The following code works fine in the REPL, but fails if executed as program.

@async begin
         udpsock = UDPSocket()
         bind(udpsock,ip"127.0.0.1",2001)
         while true
           println(String(copy(recv(udpsock))))
         end
       end

sock = UDPSocket()

send(sock,ip"127.0.0.1",2001,"Hello World from the UDP")
sleep(1.0)
close(sock)

If I execute it as program I get:

ufechner@TUD277255:~/uavtalk/logger$ julia logger.jl 
julia: /home/ufechner/julia/deps/srccache/libuv-8d5131b6c1595920dd30644cd1435b4f344b46c8/src/unix/core.c:103: uv_close: Assertion `!(handle->flags & (UV_CLOSING | UV_CLOSED))' failed.

signal (6): Aborted
while loading no file, in expression starting on line 0
raise at /build/glibc-t3gR2i/glibc-2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54
abort at /build/glibc-t3gR2i/glibc-2.23/stdlib/abort.c:89
__assert_fail_base at /build/glibc-t3gR2i/glibc-2.23/assert/assert.c:92
__assert_fail at /build/glibc-t3gR2i/glibc-2.23/assert/assert.c:101
uv_close at /home/ufechner/julia/deps/srccache/libuv-8d5131b6c1595920dd30644cd1435b4f344b46c8/src/unix/core.c:103
close at ./stream.jl:326
uvfinalize at ./stream.jl:343
unknown function (ip: 0x7f67697fd1c2)
jl_call_method_internal at /home/ufechner/julia/src/julia_internal.h:189 [inlined]
jl_apply_generic at /home/ufechner/julia/src/gf.c:1945
jl_apply at /home/ufechner/julia/src/julia.h:1392 [inlined]
run_finalizer at /home/ufechner/julia/src/gc.c:108
jl_gc_run_finalizers_in_list at /home/ufechner/julia/src/gc.c:190 [inlined]
run_finalizers at /home/ufechner/julia/src/gc.c:211
jl_atexit_hook at /home/ufechner/julia/src/init.c:253
unknown function (ip: 0x4012ef)
__libc_start_main at /build/glibc-t3gR2i/glibc-2.23/csu/../csu/libc-start.c:291
unknown function (ip: 0x401338)
Allocations: 1079467 (Pool: 1078593; Big: 874); GC: 0
Aborted (core dumped)
ufechner@TUD277255:~/uavtalk/logger$ 

Any idea?

Uwe

I got it working :slight_smile: :

@async begin
         udpsock = UDPSocket()
         bind(udpsock,ip"127.0.0.1",2001)
         i = 0
         while i < 10
           println(String(copy(recv(udpsock))))
           sleep(0.1)
         end
         close(udpsock)
       end

sock = UDPSocket()
sleep(0.1)
send(sock, ip"127.0.0.1", 2001, "Hello World from the UDP!")
sleep(2.0)
close(sock)
sleep(0.1)

But without the final sleep(0.1) it crashes. Is this to be expected?

1 Like