From: snacktime Date: 2007-07-15T15:53:32+09:00 Subject: Re: Real project -- general application structure On 7/14/07, Ricardo Jasinski wrote: > Hi Florian, > > thanks a lot for pointing me out the existence of Eventmachine; I had > missed that one completely. > > I was amazed to see how easy it is to structure the terminal > connections using EM. In less than 5 minutes after installing the gem > I could already handle connections and interpret the sensors data. > > However, I realized that it was essentially the same that my original > code was already doing (excpet it is much cleaner and way cooler!). I > can easily talk to the remote units, but I still need to find a way to > display their momentary status on a web page (which should always > display up-to-date information, and be independent of full page > reloads on the browser). > > What would you suggest; can I use EM to talk to my web server which > would be another application? Or perhaps open a pipe to it somehow? > You might take a look at using mongrel (with the swiftiply patch to have mongrel use EM) and create your own handler. That gives you a custom http server with the EM engine running. Look at the mongrel examples/simpletest.rb file. Towards the bottom it calls run, at the point EM is running. You could for example put an EM periodic timer there to fire off your checks on the remote units, and create a class variable (singleton) to hold the latest data that your handler can access whenever an http request comes in. Now you just have one program to handle everything. Chris