bartbes / love-misc-libs

Just some random libs I have lying around, now with version control!
http://docs.bartbes.com
110 stars 28 forks source link

LUBE-Testing | tcpClient is not receive messages from server (with Workaround) #7

Closed ghost closed 13 years ago

ghost commented 13 years ago

Hi.

I think the server -> client communication is broken (tcp). client -> server communication work as well, but server -> client doesn't work for me. The self.callback.recv function will not be executed. I have tested it with no rcpt (msg to all clients) and with rcpt (clientid).

I have a 'crappy workaround', but yeah ... I don't think this workaround is good (workaround is not for udp, don't know if the bug is on the udpClient too).

I changed the client:update(dt) function from LUBE.lua to this one:

function client:update(dt)
    if not self.connected then return end 
    assert(dt, "Update needs a dt!")
    -- First, let's handle ping messages.
    if self.ping then
        self.ping.timer = self.ping.timer + dt
        if self.ping.timer > self.ping.time then
            self:_send(self.ping.msg)
            self.ping.timer = 0 
        end 
    end 
    -- If a recv callback is set, let's grab
    -- all incoming messages. If not, leave
    -- them in the queue.
    if self.callbacks.recv then
        local _nil, _timeout, data = self:_receive()
        while data ~= nil and data ~= '' do
            self.callbacks.recv(data)
            _nil, _timeout, data = self:_receive()
        end 
    end 
end
bartbes commented 13 years ago

Should work now.