-
Notifications
You must be signed in to change notification settings - Fork 55
Lua API reference manual
zhaojh329 edited this page Jun 4, 2017
·
11 revisions
Init mgr context, return a handle
local ev = require("ev")
local evmongoose = require("evmongoose")
local loop = ev.Loop.new()
local mgr = evmongoose.init(loop)
Listens for the specified address, can plain udp, plain tcp, or http or https.
--an tcp server
mgr:bind("8000", ev_handle)
--an http server
mgr:bind("8000", ev_handle, {proto = "http", document_root = "/www"})
--an https server
mgr:bind("8000", ev_handle, {proto = "http", ssl_cert = "server.pem", ssl_key = "server.key", document_root = "."})
connect to http or https server
mgr:connect_http("http://www.baidu.com", ev_handle)
mgr:connect_http("https://www.baidu.com", ev_handle, {ssl_cert = "server.pem", ssl_key = "server.key"})
connect to tcp server or mqtt server
mgr:connect("localhost:1883", ev_handle)
an event callback function, when the function is called, the bottom layer will passes in 3 parameters. They are "nc", "event", "msg". "nc" is used to identify each connection, "event" represents the current event type, "msg" saves the relevant data of the current particular event.
local function ev_handle(nc, event, msg)
if evmongoose.MG_EV_HTTP_REQUEST then
...
end
end
- MG_EV_CONNECT
- MG_EV_CLOSE
- MG_EV_HTTP_REQUEST
- MG_EV_HTTP_REPLY
- MG_EV_MQTT_CONNACK
- MG_EV_MQTT_SUBACK
- MG_EV_MQTT_PUBACK
- MG_EV_MQTT_PUBLISH
- MG_EV_MQTT_CONNACK_ACCEPTED
- MG_EV_MQTT_CONNACK_UNACCEPTABLE_VERSION
- MG_EV_MQTT_CONNACK_IDENTIFIER_REJECTED
- MG_EV_MQTT_CONNACK_SERVER_UNAVAILABLE
- MG_EV_MQTT_CONNACK_BAD_AUTH
- MG_EV_MQTT_CONNACK_NOT_AUTHORIZED