Need help with UDP connection:receive problem
Posted: Sat May 09, 2020 4:13 pm
I've been working on my multiplayer game and stuck on the moment when I decided to put packet reception of the client into 'main.lua', so i don't have to call it in every object that somehow interacts with the server. I have a stage called 'hub.lua' where the connection:receive was called only once (before I moved it) to approve the connection to the server. If approval was received, the stage changed to 'Stage.lua', where the game itself was supposed to be happening. In 'Stage' I have to update multiple items that require multiple connection:receive calls.
So here's what is happening:
If I run the code and the packet reception is only in 'hub.lua', then everything is working just fine, but if I add the packet reception code to the 'chat.lua' (which is first called in 'Stage.lua') for example, the game freezes with no crash reports. The same happens if I remove packet reception code from both 'chat' and 'hub' and place it in the 'main.lua', which lead me to a conclusion that the problem is caused by call of connection:receive.
The problem is definitely is not on the server side as I have checked all packets that are being sent to the client.
Here's the code:
"hub.lua" (somewhere in the 'hub.update' function) :
'main.lua' :
Any ideas on what might be wrong?
So here's what is happening:
If I run the code and the packet reception is only in 'hub.lua', then everything is working just fine, but if I add the packet reception code to the 'chat.lua' (which is first called in 'Stage.lua') for example, the game freezes with no crash reports. The same happens if I remove packet reception code from both 'chat' and 'hub' and place it in the 'main.lua', which lead me to a conclusion that the problem is caused by call of connection:receive.
The problem is definitely is not on the server side as I have checked all packets that are being sent to the client.
Here's the code:
"hub.lua" (somewhere in the 'hub.update' function) :
Code: Select all
if _t > _updaterate then
repeat
_data = _udp:receive() --data receive problem. Possible leak
if _data ~= nil then
_currentCmd, _currentAnws = _data:match("^(%S*) (%S*)")
_data = nil
end
until not _data
_t = _t - _updaterate
end
if _currentCmd == "anwser" then
_status = _currentAnws
_currentCmd = nil
if tonumber(_status) == 1 then
gotoRoom("Stage")
elseif tonumber(_status) == 0 then
_udp:close()
_udp = Socket.udp()
connectBtn:setData(connectBtn, 0)
_status = "No slots available for this address or a connection with your address was not closed" --change to receive error
end
end
Code: Select all
function love.update(dt)
_t = _t + dt
if _udp ~= nil then
if _t > _updaterate then
repeat
local _data, msg = _udp:receive() --data receive problem. Possible leak
if _data then
_currentCmd, _currentAnws = _data:match("^(%S*) (%S*)")
_data = nil
end
until not _data
_t = _t - _updaterate
end
end
camera:update(dt)
uMouse:update(dt)
if current_room then
current_room:update(dt)
end
end