I am using eventmachine 0.8.1 on windows XP and am having very odd problems. This snippet of code gives the error that follows it. class EchoServer def receive_data data puts data send_data ">>>you sent: #{data}" if data =~ /quit/i puts "quitting" close_connection EventMachine::stop_event_loop end end end EventMachine::run { EventMachine::open_datagram_socket "127.0.0.99", port, EchoServer } Gives the error d:/ruby/lib/ruby/gems/1.8/gems/eventmachine-0.8.1-x86-mswin32/lib/eventmachine.rb:959:in `event_callback'': EventMachine::ConnectionNotBound (EventMachine::ConnectionNotBound) from d:/ruby/lib/ruby/gems/1.8/gems/eventmachine-0.8.1-x86-mswin32/lib/eventmachine.rb:223:in `release_machine'' from d:/ruby/lib/ruby/gems/1.8/gems/eventmachine-0.8.1-x86-mswin32/lib/eventmachine.rb:223:in `run'' from eventmachine_test.rb:26 This snippet of code kind of works.. module EchoServer def receive_data data puts data send_data ">>>you sent: #{data}" if data =~ /quit/i puts "quitting" close_connection EventMachine::stop_event_loop end end end EventMachine::run { EventMachine::open_datagram_socket "127.0.0.99", port, EchoServer } This works halfway and only once. The first time I call it the puts statement works but the send_data doesn''t. Any further calls don''t seem to do anything. The puts doesn''t work neither does the send_data. Obviously I am missing something here.
Jason Roelofs
2008-Jan-06 07:06 UTC
[Eventmachine-talk] Having very odd problems with UDP.
The ConnectionNotBound error is really quite misleading. It is something that needs to be changed because that''s the "catch-all" exception. I''ve seen in thrown when I had a NoMethodError in my code, and similar problems. So to be sure, wrap your code in a begin ... rescue block and see what exactly is being thrown. As for your code, I do see something slightly wrong. You should use close_connection_after_writing, because data is not sent immediately when you call send_data, but is queued up to be sent when it''s most efficient, and after the received_data block is done. Jason On Jan 6, 2008 3:30 AM, Tim Uckun <timuckun at gmail.com> wrote:> I am using eventmachine 0.8.1 on windows XP and am having very odd > problems. > > This snippet of code gives the error that follows it. > > class EchoServer > def receive_data data > puts data > send_data ">>>you sent: #{data}" > if data =~ /quit/i > puts "quitting" > close_connection > EventMachine::stop_event_loop > end > end > end > > EventMachine::run { > EventMachine::open_datagram_socket "127.0.0.99", port, EchoServer > } > > Gives the error > > d:/ruby/lib/ruby/gems/1.8/gems/eventmachine-0.8.1-x86-mswin32 > /lib/eventmachine.rb:959:in > `event_callback'': EventMachine::ConnectionNotBound > (EventMachine::ConnectionNotBound) > from d:/ruby/lib/ruby/gems/1.8/gems/eventmachine-0.8.1-x86-mswin32 > /lib/eventmachine.rb:223:in > `release_machine'' > from d:/ruby/lib/ruby/gems/1.8/gems/eventmachine-0.8.1-x86-mswin32 > /lib/eventmachine.rb:223:in > `run'' > from eventmachine_test.rb:26 > > > > This snippet of code kind of works.. > > module EchoServer > def receive_data data > puts data > send_data ">>>you sent: #{data}" > if data =~ /quit/i > puts "quitting" > close_connection > EventMachine::stop_event_loop > end > end > end > > EventMachine::run { > EventMachine::open_datagram_socket "127.0.0.99", port, EchoServer > } > > > This works halfway and only once. > > The first time I call it the puts statement works but the send_data > doesn''t. Any further calls don''t seem to do anything. The puts doesn''t > work neither does the send_data. > > > Obviously I am missing something here. > _______________________________________________ > Eventmachine-talk mailing list > Eventmachine-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/eventmachine-talk >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/eventmachine-talk/attachments/20080106/212111c9/attachment.html
Francis Cianfrocca
2008-Jan-06 09:09 UTC
[Eventmachine-talk] Having very odd problems with UDP.
On Jan 6, 2008 3:30 AM, Tim Uckun <timuckun at gmail.com> wrote:> I am using eventmachine 0.8.1 on windows XP and am having very odd > problems. > > This snippet of code gives the error that follows it. > > class EchoServer > def receive_data data > puts data > send_data ">>>you sent: #{data}" > if data =~ /quit/i > puts "quitting" > close_connection > EventMachine::stop_event_loop > end > end > end > > EventMachine::run { > EventMachine::open_datagram_socket "127.0.0.99", port, EchoServer > } > > Gives the error > > d:/ruby/lib/ruby/gems/1.8/gems/eventmachine-0.8.1-x86-mswin32 > /lib/eventmachine.rb:959:in > `event_callback'': EventMachine::ConnectionNotBound > (EventMachine::ConnectionNotBound) > from d:/ruby/lib/ruby/gems/1.8/gems/eventmachine-0.8.1-x86-mswin32 > /lib/eventmachine.rb:223:in > `release_machine'' > from d:/ruby/lib/ruby/gems/1.8/gems/eventmachine-0.8.1-x86-mswin32 > /lib/eventmachine.rb:223:in > `run'' > from eventmachine_test.rb:26 > > > > This snippet of code kind of works.. > > module EchoServer > def receive_data data > puts data > send_data ">>>you sent: #{data}" > if data =~ /quit/i > puts "quitting" > close_connection > EventMachine::stop_event_loop > end > end > end > > EventMachine::run { > EventMachine::open_datagram_socket "127.0.0.99", port, EchoServer > } > > > This works halfway and only once. > > The first time I call it the puts statement works but the send_data > doesn''t. Any further calls don''t seem to do anything. The puts doesn''t > work neither does the send_data. > > > Obviously I am missing something here. >Jason is right, the ConnectionNotBound error is very misleading. What has happened is that your Ruby code has thrown an exception, and the EM reactor loop caught it and reported it as something different. You can work around your problem by putting begin/rescue into your code to find and fix the error. Meanwhile we have to fix the reporting problem in EM. I''ve tried several different approaches to this, but they all had either performance problems or were just as confusing, only different. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/eventmachine-talk/attachments/20080106/813f29f9/attachment.html
> You can work around your problem by putting begin/rescue into your code to > find and fix the error.I have modified the code like this. port = ARGV[1].to_i ip = ARGV[0] begin module EchoServer def receive_data data puts data send_data ">>>you sent: #{data}" close_connection if data =~ /quit/i close_connection EventMachine::stop_event_loop end end end EventMachine::run { EventMachine::open_datagram_socket ip, port , EchoServer #EventMachine::start_server ip, port , EchoServer } rescue => e puts e.message EventMachine::stop_event_loop end I am using a program called sockettest to conduct all my testing http://sourceforge.net/projects/sockettest/ The results: The rescue never gets triggered. The start_server works exactly as you would expect. It listens and responds correctly. The open_datagram_socket never sends replies (or if it does then sockettest is unable to display them) If you use any IP in the 127.0.0.0/24 subnet open_datagram_socket only works once (the first time). Any subsequent sends seem to vanish into thin air. The puts never triggers. If you use a normally bound IP address it gets to the puts every time but as I said above it never seems to send anything back. Very weird.
Jason Roelofs
2008-Jan-06 17:26 UTC
[Eventmachine-talk] Having very odd problems with UDP.
On Jan 6, 2008 8:13 PM, Tim Uckun <timuckun at gmail.com> wrote:> > You can work around your problem by putting begin/rescue into your code > to > > find and fix the error. > > I have modified the code like this. > > port = ARGV[1].to_i > ip = ARGV[0] > > begin > module EchoServer > def receive_data data > puts data > send_data ">>>you sent: #{data}" > close_connection > if data =~ /quit/i > close_connection > EventMachine::stop_event_loop > end > end > end > > EventMachine::run { > EventMachine::open_datagram_socket ip, port , EchoServer > #EventMachine::start_server ip, port , EchoServer > } > > rescue => e > puts e.message > EventMachine::stop_event_loop > end > > > I am using a program called sockettest to conduct all my testing > http://sourceforge.net/projects/sockettest/ > > The results: > > The rescue never gets triggered. > > The start_server works exactly as you would expect. It listens and > responds correctly. > > The open_datagram_socket never sends replies (or if it does then > sockettest is unable to display them) > > If you use any IP in the 127.0.0.0/24 subnet open_datagram_socket only > works once (the first time). Any subsequent sends seem to vanish into > thin air. The puts never triggers. > > If you use a normally bound IP address it gets to the puts every time > but as I said above it never seems to send anything back. > > Very weird. > _______________________________________________ > Eventmachine-talk mailing list > Eventmachine-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/eventmachine-talk >The idea would be to wrap just the code that gets called: module EchoServer def receive_data data begin puts data send_data ">>>you sent: #{data}" close_connection if data =~ /quit/i close_connection EventMachine::stop_event_loop end rescue => ex # do stuff with exception here end end end EventMachine::run { EventMachine::open_datagram_socket ip, port , EchoServer #EventMachine::start_server ip, port , EchoServer } Wrapping the whole bit isn''t going to do you any good. Outside of that not really making any sense, received_data is itself wrapped in a begin ... rescue block, and *that* is where ConnectionNotBound is thrown. Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/eventmachine-talk/attachments/20080106/c380875e/attachment.html
> > The idea would be to wrap just the code that gets called:I tried that first. Since I was not catching exceptions I moved out to the entire codebase just in case something was happening upstream.> } > Wrapping the whole bit isn''t going to do you any good. Outside of that not > really making any sense, received_data is itself wrapped in a begin ... > rescue block, and *that* is where ConnectionNotBound is thrown. >Maybe I should try on my mac or linux machines. The code definitely has to work on windows so that''s why I am developing in windows. In a nutshell. If the UDP listener is listening on the 127 IPs it only accepts a packet the first time. All subsequent packets seem to be ignored. If it''s listening on "normal" IP addresses it receives all packets. send_data never works with UDP. UDP is stateless so maybe send_data isn''t supposed to work unless I set up a listener right?