sock.lua icon indicating copy to clipboard operation
sock.lua copied to clipboard

Server:sendToPeer() Gets Serialized Twice

Open LazyInn opened this issue 7 years ago • 2 comments

Server:sendToPeer() passes serialized data to Client:send(), which serializes it again. Causing event to not fire client side since they receive the serialized data as the event name. Easy fix:

function Server:sendToPeer(peer, event, data) peer:send(event, data) end

LazyInn avatar Jan 26 '18 11:01 LazyInn

Still not fixed

griffi-gh avatar Aug 18 '20 17:08 griffi-gh

~It is updated in the latest master, but not in the release 0.3.0~ It was updated, but is still not fixed, try the solution @LazyInn suggested, by changing sendToPeer as follows:

--- Send a message to a single peer. Useful to send data to a newly connected player
-- without sending to everyone who already received it.
-- @tparam enet_peer peer The enet peer to receive the message.
-- @tparam string event The event to trigger with this message.
-- @param data data to send to the peer.
--@usage
--server:sendToPeer(peer, "initialGameInfo", {...})
function Server:sendToPeer(peer, event, data)
    --local serializedMessage = self:__pack(event, data)

    self.packetsSent = self.packetsSent + 1

    peer:send(event, data)
    --peer:send(serializedMessage, self.sendChannel, self.sendMode)

    self:resetSendSettings()
end

Ismoh avatar Nov 18 '21 13:11 Ismoh