[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: HTTP long polling with Lua
- From: David Hollander <dhllndr@...>
- Date: Wed, 20 Jul 2011 21:47:07 -0500
> Looks like it is not possible to do this in WSAPI without some serious
> low-level coding...
I have a lightweight Lua web server here that uses callbacks instead
of coroutines [1]. Handlers take the following format:
http.GET['/polldata'] = function(c) ... end
Where c is a connection table where the reply method can be called at
any time. You could maybe do something like the following:
http.serve(8080, {session.check})
http.GET['/messages'] = function(c)
print('query string', c.req.qstr)
if not c.user then c:reply(401, 'Must authenticate first')
else get_message(c.user, function(msg)
c:reply(200, message)
end)
end
Where get_message could be a function that accepts a string and a
callback. Then you could use a put_message function to get\run
callbacks from a table. Should be more straightforward, simpler and
faster than throwing an extra C server\socket abstraction like
Mongrel\zmq into the stack. Let me know if you are interested in using
this and I'll put up some example applications and documentation this
weekend.
[1] https://github.com/davidhollander/ox
On Wed, Jul 20, 2011 at 6:27 PM, Josh Simmons <simmons.44@gmail.com> wrote:
>
> On Thu, Jul 21, 2011 at 9:21 AM, Alexander Gladysh <agladysh@gmail.com> wrote:
> > On Thu, Jul 21, 2011 at 03:18, Josh Simmons <simmons.44@gmail.com> wrote:
> >> On Thu, Jul 21, 2011 at 9:15 AM, Alexander Gladysh <agladysh@gmail.com> wrote:
> >>> 2011/7/21 Ignacio Burgueño <ignaciob@inconcertcc.com>:
> >>>> Shameless plug...
> >>>> LuaNode ?
> >>>> https://github.com/ignacio/LuaNode
> >
> >>> Can you please give me a little hint on how to actually do long polling with it?
> >
> >> Tir supports long polling as default, there's no magic required.
> >
> > The actual question (for Tir, LuaNode, WSAPI or whatever framework):
> >
> > How to block a client "request handler" until we receive an event for
> > that client (and until connection is broken) without blocking all
> > other clients (and without busy loop etc.)?
> >
> > Alexander.
> >
> >
>
> In Tir you yield to the dispatch engine. It the incoming data off the
> zmq socket and resumes the appropriate client co-routine when
> necessary.
>