|
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.
RatchetThe 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.
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() |
||||||
|
||||||