Software /
code /
verse
Comparison
init.lua @ 54:1a2a3d598254
verse: Take advantage of server.lua's new onconnect callback for a more robust "connected" event
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 06 May 2010 10:27:11 +0100 |
parent | 53:091ff10eb51c |
child | 55:163beb198646 |
comparison
equal
deleted
inserted
replaced
53:091ff10eb51c | 54:1a2a3d598254 |
---|---|
127 | 127 |
128 -- Listener factory | 128 -- Listener factory |
129 function new_listener(stream) | 129 function new_listener(stream) |
130 local conn_listener = {}; | 130 local conn_listener = {}; |
131 | 131 |
132 function conn_listener.onconnect(conn) | |
133 stream.connected = true; | |
134 stream.send = function (stream, data) stream:debug("Sending data: "..tostring(data)); return conn:write(tostring(data)); end; | |
135 stream:event("connected"); | |
136 end | |
137 | |
132 function conn_listener.onincoming(conn, data) | 138 function conn_listener.onincoming(conn, data) |
133 stream:debug("Data"); | 139 stream:event("incoming-raw", data); |
134 if not stream.connected then | |
135 stream.connected = true; | |
136 stream.send = function (stream, data) stream:debug("Sending data: "..tostring(data)); return conn:write(tostring(data)); end; | |
137 stream:event("connected"); | |
138 end | |
139 if data then | |
140 stream:event("incoming-raw", data); | |
141 end | |
142 end | 140 end |
143 | 141 |
144 function conn_listener.ondisconnect(conn, err) | 142 function conn_listener.ondisconnect(conn, err) |
145 stream.connected = false; | 143 stream.connected = false; |
146 stream:event("disconnected", { reason = err }); | 144 stream:event("disconnected", { reason = err }); |