23.03.2018, 06:04
Hi,
I am using the following UDP server code for taking requests from the LM objects. effectively the websockets client needs to running asynchronously so it doesn't block the udp server running. In the past I have used copas to do this.
I am using the following UDP server code for taking requests from the LM objects. effectively the websockets client needs to running asynchronously so it doesn't block the udp server running. In the past I have used copas to do this.
Code:
local server = usocket.udp()
server:setsockname("127.0.0.1",53450)
function handler(skts)
skts = copas.wrap(skts)
alert("UDP connection handler")
while true do
local s, err
alert("UDP receiving..")
s, erro = skts:receive(2048)
if not s then
alert("Receive error: %s", erro)
break
end
alert("Received data, bytes: %s",s)
-- send to the websocket
client:send(s)
end
end
copas.addserver(server, handler, 1)