Elixir gen_udp example
Quick and dirty UDP server/client… open two shell iex
sessions:
In first session (this will be the server):
iex(1)> {:ok, socket} = :gen_udp.open(3000, [:binary , active: false])
{:ok, #Port<0.7>}
From the second session:
iex(4)> {:ok, socket} = :gen_udp.open(3001)
{:ok, #Port<0.8>}
iex(5)> :gen_udp.send(socket, {0,0,0,0}, 3000, "yo")
:ok
Back in the first session:
iex(4)> {:ok, data} = :gen_udp.recv(socket, 0)
{:ok, { {127, 0, 0, 1}, 3001, "yo"} }
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;