Kraken

Introduction

Kraken is a simple dispatcher that allows the programmers develop their own network servers with no need thinking about socket problems.

Kraken is the low-level part of the LuaWsgi Project, but it can be used apart.

Portuguese speakers can refer to LuaWsgi Changelog for more informations.

Use

The kraken binary works pretty like lua51 binary, but with a little difference: it automatically imports (require) the kraken module, with its own socket support.

Kraken does not work with LuaSocket!!!

Functions

The kraken module offers four functions:

  1. kraken.registerApplication(application_coroutine) – receives a thread (coroutine) and registers it as the Lua state to process the connections.
    The function of the thread must have two arguments: the first receives the client socket and the second receives a table with two keys:
  2. kraken.registerAddress(address_table) – receives a table representing the server socket, i.e., the address and the port to listen.
    The table must be two keys:
  3. kraken.registerUser(uid) – receives the uid of the user who must run the application.
    This function is optional.
  4. kraken.socket(domain, type, protocol) – returns a master socket. The three parameters are: This function is optional.

Tables

Socket object

The object returned by the kraken.socket() has some useful methods.

Example

local app = coroutine.create(function (skt, addr)
	print("Connection from " .. addr.host .. ":" .. addr.port)
	skt:rawsend "> "
	print("Received: " .. skt:receive())
	skt:send("Ok\n")
end)

assert(kraken.registerApplication(app))
assert(kraken.registerAddress { host = "*", port =  8001 })
assert(kraken.loop())

Rodrigo Cacilhas