Software /
code /
verse
Changeset
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 (2010-05-06) |
parents | 53:091ff10eb51c |
children | 55:163beb198646 |
files | init.lua |
diffstat | 1 files changed, 7 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/init.lua Thu May 06 10:26:16 2010 +0100 +++ b/init.lua Thu May 06 10:27:11 2010 +0100 @@ -129,16 +129,14 @@ function new_listener(stream) local conn_listener = {}; + function conn_listener.onconnect(conn) + stream.connected = true; + stream.send = function (stream, data) stream:debug("Sending data: "..tostring(data)); return conn:write(tostring(data)); end; + stream:event("connected"); + end + function conn_listener.onincoming(conn, data) - stream:debug("Data"); - if not stream.connected then - stream.connected = true; - stream.send = function (stream, data) stream:debug("Sending data: "..tostring(data)); return conn:write(tostring(data)); end; - stream:event("connected"); - end - if data then - stream:event("incoming-raw", data); - end + stream:event("incoming-raw", data); end function conn_listener.ondisconnect(conn, err)