Closed ghost closed 13 years ago
This only happens if the handshake is not set (or nil), which is invalid operation anyway. (If this, for some reason, does happen with a handshake set, please provide some code.)
the handshake is set ... clientside and serverside ... same with ping
require 'lib.hump.class'
require 'lib.LUBE.LUBE'
-- We use Class Commons
assert(common and common.class, "A Class Commons implementation is required")
local server = {}
function server:init()
print('[myon2d-debug] initialize server')
self.conf = {
port = 2842,
handshake = 'dev',
ping = true,
pingtime = 4,
pingmsg = 'ping',
}
self.clients = {}
self.server = lube.tcpServer()
self.server.handshake = self.conf.handshake
self.server.callbacks.recv = function(rawData, clientid) self:onReceive(rawData, clientid) end
self.server.callbacks.connect = function(clientid) self:onConnect(clientid) end
self.server.callbacks.disconnect = function(clientid) self:onDisconnect(clientid) end
self.server:setPing(self.conf.ping, self.conf.pingtime, self.conf.pingmsg)
self.server:listen(self.conf.port)
self.status = 'initialized'
end
function server:update(dt)
if self.status == 'initialized' then
self.server:accept()
self.server:update(dt)
end
end
function server:onReceive(rawData, clientid)
end
function server:onConnect(clientid)
local ip, port = clientid:getpeername()
table.insert(self.clients,{ip=ip, port=port})
print('[myon2d-debug] connect from: '..ip..'/'..port)
end
function server:onDisconnect(clientid)
print(clientid)
-- local ip, port = clientid:getpeername()
-- for k, v in pairs(self.clients) do
-- if ip == v.ip and port == v.port then
-- table.remove(self.clients, k)
-- end
-- end
-- print('[myon2d-debug] disconnect from: '..ip..'/'..port)
end
-- Create our classes
myon2d.Server = common.class('myon2d.Server', server)
this is the relevant serverside code-part
if u need the whole project, i can create a git repo
thank you for help
Nice catch.
When a client disconnects, time-outs, the clientid argument on the disconnect-callback is everytime no Messages. Is this a Bug?