Created
December 14, 2009 10:43
-
-
Save epitron/255965 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#--------------------------------------------------------------------------- | |
# The first one receives and prints a datagram: | |
#--------------------------------------------------------------------------- | |
require 'rubygems' | |
require 'eventmachine' | |
module A | |
def receive_data a | |
p a | |
end | |
end | |
EM.run { | |
p "Listening on 9600" | |
EM.open_datagram_socket "localhost", 9600, A | |
} |
This file contains hidden or 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
#--------------------------------------------------------------------------- | |
# The third one sends a datagram to start off the process: | |
#--------------------------------------------------------------------------- | |
require 'rubygems' | |
require 'eventmachine' | |
module G | |
def post_init | |
send_datagram "AAA", "localhost", 9601 | |
end | |
end | |
EM.run { | |
EM.open_datagram_socket "localhost", 0, G | |
} |
This file contains hidden or 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
#--------------------------------------------------------------------------- | |
# The second one waits to receive a datagram, then sends it to a different | |
# port. | |
#--------------------------------------------------------------------------- | |
require 'rubygems' | |
require 'eventmachine' | |
module A | |
def receive_data a | |
p a | |
send_datagram "<#{a}>", "localhost", 9600 | |
end | |
end | |
EM.run { | |
p "Listening on 9601, sending to 9600" | |
EM.open_datagram_socket "localhost", 9601, A | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment