Last active
October 1, 2020 18:17
-
-
Save cmol/1656b1780df33e7d435f3ab01b8cbe12 to your computer and use it in GitHub Desktop.
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
def echo_listener(socket, linklocal_addr, multicast_addr, multicast_port, | |
flags, msg_length) | |
loop do | |
# Listen for messages of up to specified length | |
message, client = socket.recvfrom(msg_length) | |
# Extract client information given as array and log connection | |
addr_info = Addrinfo.new(client) | |
# We are not interested in messages from our selves | |
next if addr_info.ip_address == linklocal_addr | |
# Write out the received message | |
puts message | |
# Only reply if a request is send. We will make infinite packet loops | |
# in our network if we don't do this | |
if(message.split.first == "[REQUEST]") | |
puts "========= Sending echo REPLY to #{addr_info.ip_address}" | |
socket.send("[REPLY] Hello from #{addr_info.ip_address}", | |
flags, multicast_addr, multicast_port) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment