2 if mg.lua_type ~= "websocket" then
3 mg.write("HTTP/1.0 403 Forbidden\r\n")
4 mg.write("Connection: close\r\n")
11 -- table of all active connection
14 -- function to get a client identification string
16 local ri = allConnections[tab.client].request_info
17 return ri.remote_addr .. ":" .. ri.remote_port
20 -- Callback to accept or reject a connection
22 allConnections[tab.client] = tab
23 return true -- return true to accept the connection
26 -- Callback for "Websocket ready"
28 return true -- return true to keep the connection open
31 -- Callback for "Websocket received data"
33 mg.write(1, tab.data);
34 return true -- return true to keep the connection open
37 -- Callback for "Websocket is closing"
39 allConnections[tab.client] = nil