Created
March 5, 2019 14:37
-
-
Save haakov/c5635551d7d8c69d873eec7cc8610a2e to your computer and use it in GitHub Desktop.
Elixir functions for mocking UDP Broadcast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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