Skip to content

Instantly share code, notes, and snippets.

@haakov
Created March 5, 2019 14:37
Show Gist options
  • Save haakov/c5635551d7d8c69d873eec7cc8610a2e to your computer and use it in GitHub Desktop.
Save haakov/c5635551d7d8c69d873eec7cc8610a2e to your computer and use it in GitHub Desktop.
Elixir functions for mocking UDP Broadcast
defmodule Elevator.BCMock do
def bcast_serve do
{:ok, portid} = :gen_udp.open(15660, [:binary, active: true])
server_loop(portid)
end
def server_loop(portid) do
receive do
{:udp, _, _, _, msg} ->
:gen_udp.send(portid, {127, 0, 0, 1}, 15657, msg)
:gen_udp.send(portid, {127, 0, 0, 1}, 15658, msg)
:gen_udp.send(portid, {127, 0, 0, 1}, 15659, msg)
end
server_loop(portid)
end
end
# Send to 15660, receive on 15657, 15658 and 15659
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment