[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: "ratchet" socket control library
 
- From: "Ian Good" <ian.good@...>
 
- Date: Wed, 28 Sep 2011 10:10:48 -0400 (EDT)
 
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: http://25thandclement.com/~william/projects/dns.c.html)
 * 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: http://ratchet.icgood.net/
Source: http://github.com/icgood/ratchet
Ian Good
------------------------------------------------------------------------
require "ratchet"
require "ratchet.http.client"
function http_query(i)
    local rec = ratchet.socket.prepare_uri("tcp://google.com:80")
    local socket = ratchet.socket.new(rec.family, rec.socktype, rec.protocol)
    if not socket:connect(rec.addr) then
        error("Could not connect to google.com on port 80!")
    end
    local client = ratchet.http.client.new(socket)
    local code, message, headers, data = client:query("GET", "/")
    assert(200 == code, "[200] != [%s] (%s)":format(code, message))
    print(i .. ": Received html data from google.com.")
end
kernel = ratchet.new()
for i=1,10 do
    kernel:attach(http_query, i)
end
kernel:loop()