lua-users home
lua-l archive

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

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.


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!")

    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")

kernel =
for i=1,10 do
    kernel:attach(http_query, i)