Home
Ratchet Library :: Index
API  ·  Manual
The latest version of ratchet supports (and requires) Lua 5.2. Please use a tagged version less than 0.8.0 for Lua 5.1 support.

Ratchet

The purpose of the ratchet library is to provide in Lua an asynchronous socket control mechanism for large numbers of sockets without using OS-level threads or losing the ease of synchronous socket programming.

  1. README
  2. License
  3. Download [Repository]
  4. Bug Reports
  5. Installation
  6. Complete API Reference [Archive]
  7. Usage Manual

 

require "ratchet"
require "ratchet.http.client"

function http_query(i)
    local rec = ratchet.socket.prepare_tcp("google.com", 80)
    local socket = ratchet.socket.new(rec.family, rec.socktype, rec.protocol)
    socket:connect(rec.addr)

    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

local kernel = ratchet.new(function ()
    for i=1, 10 do
        ratchet.thread.attach(http_query, i)
    end
end)
kernel:loop()



Last modified:  Mon, 23 Apr 2012 11:21:54 -0400
Author:  ian.good