Hey folks, I was playing around with adding Comet (a javascript technology used to receive events without AJAX polling) support to Mongrel. More info about Comet here: http://en.wikipedia.org/wiki/Comet_%28programming%29) I sort of got it working. My code is available at: http;//cyll.org/comet.tar.gz Run comet.rb from inside the directory and point your browser at: http://localhost:5555/ The fly in the ointment is that until a Comet request finishes, that URL mount point stops responding. I assume this is because of how thread management happens in Mongrel. Leaving the request unfinished like I do is probably uncool. One way to sort of work around the problem is to use a dispatcher that registers a new handler at a unique URL for each Comet user. You can see that both the main page and: http://localhost:5555/2 work simultaneous. And neither affects other mounted handlers, so you can also access: http://localhost:5555/moose Anyways, I''m not really doing anything with this code and I''m sure it has problems, but I thought I''d put it out there in case anyone else wanted to play around with Mongrel and Comet. Mongrel rocks, Topher Cyll
On Wed, 2006-08-09 at 23:45 -0700, Topher Cyll wrote:> Hey folks, > > I was playing around with adding Comet (a javascript technology used > to receive events without AJAX polling) support to Mongrel. More info > about Comet here: > > http://en.wikipedia.org/wiki/Comet_%28programming%29) > > I sort of got it working. My code is available at: > > http;//cyll.org/comet.tar.gz >Pretty cool. So you''re using a chunked encoding to stream out the new data. One thing: @response.write(sprintf("%x;\r\n", size)) ... @response.write("0;\r\n") You don''t need the ";". That''s only required if you add parameters to the chunked encoding header. Just give the size (in hex). I''ve contemplated doing chunked encodings for Mongrel, but I still have the problem that frameworks do their headers and body out of order, so it gets ugly (and also most proxies don''t grok chunked encoding).> The fly in the ointment is that until a Comet request finishes, that > URL mount point stops responding. I assume this is because of how > thread management happens in Mongrel. Leaving the request unfinished > like I do is probably uncool. >That shouldn''t happen. Mongrel isn''t locking or anything when running, so you should be able to server multiple requests. I''ll take a look at this further.> One way to sort of work around the problem is to use a dispatcher that > registers a new handler at a unique URL for each Comet user. You can > see that both the main page and: > > http://localhost:5555/2 > > work simultaneous. And neither affects other mounted handlers, so you > can also access: > > http://localhost:5555/moose > > Anyways, I''m not really doing anything with this code and I''m sure it > has problems, but I thought I''d put it out there in case anyone else > wanted to play around with Mongrel and Comet.And no idea why that would work. Like I said, no locking in mongrel but I''ll look at it. Cool job. If you get a chance to work this further keep sending me feedback and code. -- Zed A. Shaw http://www.zedshaw.com/ http://mongrel.rubyforge.org/ http://www.railsmachine.com/ -- Need Mongrel support?
Zed,> You don''t need the ";". That''s only required if you add parameters to > the chunked encoding header. Just give the size (in hex).Good to know!> I''ve contemplated doing chunked encodings for Mongrel, but I still have > the problem that frameworks do their headers and body out of order, so > it gets ugly (and also most proxies don''t grok chunked encoding).Ah, I noticed this didn''t seem to work at work (we have a proxy).> That shouldn''t happen. Mongrel isn''t locking or anything when running, > so you should be able to server multiple requests. I''ll take a look at > this further.Hmm, interesting. It would be cool if this could be used more generally. Let me know if you figure it out what''s happening! Topher
On Thu, 2006-08-10 at 11:27 -0700, Topher Cyll wrote:> Zed, >> > That shouldn''t happen. Mongrel isn''t locking or anything when running, > > so you should be able to server multiple requests. I''ll take a look at > > this further. > > Hmm, interesting. It would be cool if this could be used more > generally. Let me know if you figure it out what''s happening!This won''t happen for a very long time. So, if you want to get this working you''ll have to pitch in and figure it out for yourself. Sorry but I''ve got to get Mongrel working for the normal usage before I jump into weirdness like comet. Keep trying though. -- Zed A. Shaw http://www.zedshaw.com/ http://mongrel.rubyforge.org/ http://www.railsmachine.com/ -- Need Mongrel support?
> This won''t happen for a very long time. So, if you want to get this > working you''ll have to pitch in and figure it out for yourself. Sorry > but I''ve got to get Mongrel working for the normal usage before I jump > into weirdness like comet. > > Keep trying though.Yeah, no worries. =) I''ll poke around when I find some free time. -Toph