Page 1 of 1

[solved] lua socket - udp protocol

Posted: Fri Jul 03, 2015 5:59 pm
by Joe Black
I am programming a server receiving message from many clients

I was wondering how the udp message received are stored.
In the tutorial : networking with udp, the server loop is

Code: Select all

data = udp:receivefrom()
if data then
   ...
end
socket.sleep(0.01)
while timeout is set to 0

so message are handled everytime or every 0.01 s

In my code I want to pull all messages every 0.1 second or less
and at this rate many message can have been received between 2 pull
but messages aren't stored in a stack, isn't it ?
If there is no stack, the best implementation seem to be a thread that store them in a stack ?
if there is a stack can I do

Code: Select all

data,_,_=udp:receivefrom()
while data do
   data=udp:receivefrom()
end
?

thanks for your help

Re: lua socket - udp protocol

Posted: Fri Jul 03, 2015 9:23 pm
by Joe Black
Ok sorry guys, with little more research I finally got my answer

the client code of the tutorial say explicitly what I wanted to know :

Code: Select all

-- there could well be more than one message waiting for us, so we'll
-- loop unbtil we run out
repeat
   data, msg= udp:receive()
until not data