# UDP receive and send with julia

**URL:** <https://discourse.julialang.org/t/udp-receive-and-send-with-julia/62349>\
**Category:** New to Julia\
**Created:** [June 3, 2021, 7:03pm UTC](https://discourse.julialang.org/t/udp-receive-and-send-with-julia/62349 "2021-06-03T19:03:53Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![pbayer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbayer/32/11675_2.png) [@pbayer](https://discourse.julialang.org/u/pbayer)\
**Post date:** [June 4, 2021, 9:40am UTC](https://discourse.julialang.org/t/udp-receive-and-send-with-julia/62349/2 "2021-06-04T09:40:45Z")

</div>

> [@Beh123](#):
>
> ```julia
> using Sockets
> function recdata()
> @async begin
> sock=UDPSocket()
> bind(sock,ip"x.x.x.x",port)
> while true
> mydata=reinterpret(Int8,recv(sock)) # ??
> func1(mydata)
> end ## this loop will never terminate
> close(sock)
> end
> end
> 
> function func1(data)
> ####some operation that take maximum 1 second
> senddata(output);
> end
> function senddata(output)
> data=reinterpret(Int8,output) ## ???
> soc=UDPSocket()
> send(soc, ip"y.y.y.y",port2,data)
> sleep(0.2)
> end
> 
> ```

I reformatted your code using triple backticks (see [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757)).

Normally you will use some [serialization](https://docs.julialang.org/en/v1.6/stdlib/Serialization/) (`serialize` and `deserialize`) to transmit data via an UDP socket (See also [GitHub - JuliaIO/JSON.jl: JSON parsing and printing](https://github.com/JuliaIO/JSON.jl)). Can `reinterpret` work in your case? Transmission over UDP is done in `UINT8`.

---

_[View the full topic](https://discourse.julialang.org/t/udp-receive-and-send-with-julia/62349)._
