I am trying to send UDP packets (160 bytes tops), but for some reason EventMachine only sends a one initialization packet after which no packets can be sent. I have tried using send_datagram and send_data (its part of an API, so the initialization packets that are sent are using the same method as the others) but to no avail. Ethereal says that no packets are being sent and I can''t find an output from ruby with debug. The code can be found in my svn http://www.nebulargauntlet.org/svn/ng/trunk. The problems are within the files "lib/game.rb", "lib/network.rb", and "lib/ship.rb".
Will look at your code. If I can''t isolate the relevant code quickly I''ll ask you for a small sample that shows the problem. On 6/9/06, Steven Davidovitz <steviedizzle at gmail.com> wrote:> > I am trying to send UDP packets (160 bytes tops), but for some reason > EventMachine only sends a one initialization packet after which no > packets can be sent. I have tried using send_datagram and send_data (its > part of an API, so the initialization packets that are sent are using > the same method as the others) but to no avail. Ethereal says that no > packets are being sent and I can''t find an output from ruby with debug. > The code can be found in my svn > http://www.nebulargauntlet.org/svn/ng/trunk. The problems are within the > files "lib/game.rb", "lib/network.rb", and "lib/ship.rb". > > _______________________________________________ > 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/20060609/f6ae710c/attachment.htm
Steven, from looking at your code, you may be trying to run the EventMachine more than once on different threads. EventMachine raises an exception if you try to run it while its already running, and in Ruby, an uncaught exception on a thread will silently kill the thread. Please try putting a try or ensure around your calls to EventMachine::run to see if that''s the problem. If this is the problem, then we''ll discuss how to restructure this application without threads, which is part of the point of using EventMachine. On 6/9/06, Steven Davidovitz <steviedizzle at gmail.com> wrote:> > I am trying to send UDP packets (160 bytes tops), but for some reason > EventMachine only sends a one initialization packet after which no > packets can be sent. I have tried using send_datagram and send_data (its > part of an API, so the initialization packets that are sent are using > the same method as the others) but to no avail. Ethereal says that no > packets are being sent and I can''t find an output from ruby with debug. > The code can be found in my svn > http://www.nebulargauntlet.org/svn/ng/trunk. The problems are within the > files "lib/game.rb", "lib/network.rb", and "lib/ship.rb". > > _______________________________________________ > 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/20060609/2365ce80/attachment-0001.htm
Francis Cianfrocca wrote:> Steven, from looking at your code, you may be trying to run the > EventMachine more than once on different threads. EventMachine raises > an exception if you try to run it while its already running, and in > Ruby, an uncaught exception on a thread will silently kill the thread. > Please try putting a try or ensure around your calls to > EventMachine::run to see if that''s the problem. > > If this is the problem, then we''ll discuss how to restructure this > application without threads, which is part of the point of using > EventMachine. > > On 6/9/06, * Steven Davidovitz* <steviedizzle at gmail.com > <mailto:steviedizzle at gmail.com>> wrote: > > I am trying to send UDP packets (160 bytes tops), but for some reason > EventMachine only sends a one initialization packet after which no > packets can be sent. I have tried using send_datagram and > send_data (its > part of an API, so the initialization packets that are sent are using > the same method as the others) but to no avail. Ethereal says that no > packets are being sent and I can''t find an output from ruby with > debug. > The code can be found in my svn > http://www.nebulargauntlet.org/svn/ng/trunk. The problems are > within the > files "lib/game.rb", "lib/network.rb", and "lib/ship.rb". > > _______________________________________________ > Eventmachine-talk mailing list > Eventmachine-talk at rubyforge.org > <mailto:Eventmachine-talk at rubyforge.org> > http://rubyforge.org/mailman/listinfo/eventmachine-talk > <http://rubyforge.org/mailman/listinfo/eventmachine-talk> > > > ------------------------------------------------------------------------ > > _______________________________________________ > Eventmachine-talk mailing list > Eventmachine-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/eventmachine-talkYep, that seems to be the problem. The thread dies a couple seconds after loading the map. If you have any suggestions or examples for the app that would be great. Thanks, Steven
On Jun 9, 2006, at 9:22 PM, Francis Cianfrocca wrote:> Steven, from looking at your code, you may be trying to run the > EventMachine more than once on different threads. EventMachine > raises an exception if you try to run it while its already running, > and in Ruby, an uncaught exception on a thread will silently kill > the thread.You can shut this behavior off by calling: Thread.abort_on_exception = true at the top of your program, or running Ruby in debug mode (pass the - d option). Just FYI. James Edward Gray II
Steven, can you give me a quick description of the flow of this app? Then I can suggest an alternate structure that leverages the strengths of the eventmachine. Thanks. James, thanks for the tip about errors on threads- that''s something I''ve been wanting to know for a while. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/eventmachine-talk/attachments/20060610/f6f7b846/attachment.htm
Francis Cianfrocca wrote:> Steven, can you give me a quick description of the flow of this app? > Then I can suggest an alternate structure that leverages the strengths > of the eventmachine. Thanks. > > James, thanks for the tip about errors on threads- that''s something > I''ve been wanting to know for a while. > ------------------------------------------------------------------------ > > _______________________________________________ > Eventmachine-talk mailing list > Eventmachine-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/eventmachine-talkWell it is a multiplayer game, so there are packets constantly being exchanged between the game and server. The packets are usually ~60-100bytes in size and are sent ~30 times a second. I was thinking of using eventmachine because of some speed issues and (I think) blocking issues with Ruby''s networking.
Well it is a multiplayer game, so there are packets constantly being> exchanged between the game and server. The packets are usually > ~60-100bytes in size and are sent ~30 times a second. I was thinking of > using eventmachine because of some speed issues and (I think) blocking > issues with Ruby''s networking.Using an event based model seems appropriate for a game server. Most likely you are doing something along the lines of taking in the packets, possibly verifying that they are valid, updating the internal game model, and then forwarding update messages to the other players? The main difference from a threaded server is that with something like EventMachine you store all the packets, or events, in queues. Then the single server thread iterates over the queues passing events to handlers, which can in turn generate more events. You can improve performance using thread pools and/or multiple machines to handle events, but for starters a single thread can take you a long way. In the next version of event machine a distributed game or simulation might be a nice tutorial application...