lua-users home
lua-l archive

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

On Thu, Sep 29, 2011 at 12:10 AM, Ian Good <> wrote:
> Hey all,
> Wanted to introduce ratchet, a new library I've been working on. Ratchet is a socket mechanism similar to Python's gevent or a combination of Lua's luasocket+copas+ssl. The idea is, your code looks synchronous, but while waiting for one event it works on another. I attached an example at the bottom of this message.
> Asynchronous, "thread-like" access to:
>  * TCP/UDP socket client and server support
>  * SSL socket wrapper
>  * DNS queries (thanks to dns.c:
>  * Timing mechanisms (via timerfd)
>  * ZeroMQ messaging library
> Extra mechanisms:
>  * Buffered sockets
>  * HTTP/1.0 client and server sample library
>  * SMTP client and server sample library
> The code includes 20 integration-style tests covering all major features and extensive API documentation. The website includes an extensive usage manual and the API docs.
> Website:
> Source:
> Ian Good
> ------------------------------------------------------------------------
> require "ratchet"
> require "ratchet.http.client"
> function http_query(i)
>    local rec = ratchet.socket.prepare_uri("tcp://")
>    local socket =, rec.socktype, rec.protocol)
>    if not socket:connect(rec.addr) then
>        error("Could not connect to on port 80!")
>    end
>    local client =
>    local code, message, headers, data = client:query("GET", "/")
>    assert(200 == code, "[200] != [%s] (%s)":format(code, message))
>    print(i .. ": Received html data from")
> end
> kernel =
> for i=1,10 do
>    kernel:attach(http_query, i)
> end
> kernel:loop()

This looks really fantastic, I'm getting it set up to have a play now.

One minor and bloody annoying (damn you lua package maintainers
everywhere) thing is that the .pc file is named lua5.1 on debian based
systems, and lua51 on some others iirc. Not sure if there's an easy
way to support these various names in the autotools script.

The lua detection seems a bit hairy too, I had to patch it slightly to
get it to detect interpreter version properly, would it not be easier
to just search with pkg-config and be done with it? It wasn't finding
the right headers either but I gave up on that problem and just
inserted a pkg-config lua check into the build.

I had to disable SSLv2 as well because it has been removed from debian
OpenSSL due to vulnerabilities.

It has built now though! So I'll get to the real business.