lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Feb 8, 2011, at 9:45 AM, Michal Kottman wrote:

>>> While we are at it, here are my very own 500 lines worth of dinky HTTP server... and it doesn't even need LuaSocket :P
>> Man, that is such cool code that I don't understand how it actually
>> works ;)  In particular, how does it do the basic networking layer?
> Reading the source, it looks like it uses by default io.stdin and
> io.stdout, or anything that supports the :read() and :write() methods
> (i.e. sockets). 

Right, HTTP.lua works in term of a subset of the file io API [1][2] so it doesn't concern itself with networking per se. Just with the HTTP protocol itself.

So it can be run directly from the terminal, avoiding the entire network stack altogether. Handy for development/debugging. 

Or over a tcp wrapper such as D.J. Bernstein's tcpserver [3], leaving network management to these who know best :P

For example, this is how the online demo of Nanoki [4] runs:

exec bin/tcpserver -c 100 -qRHlOD 0 3388 bin/timelimit 60 bin/lua Nanoki.lua .

And of course, it can use LuaSocket as well [5] :)

For example:

HTTP[ '/' ] = function() return 'Hello world' end TCPServer( '', 1080 )( HTTP )

The embedded server can be used directly, or in conjunction with something like nginx [6] to provide a pool of long running application instances.

> Does that mean that it can work cleanly with FCGI as a "sub-server"?

Perhaps. Never tried :)