I'm using Corona SDK to make a simple app that requires luasocket. Corona SDK support luasocket to do async http req.
But I want to use UDP from luasocket. UDP receive() method from luasocket is blocking until it receives a message.
Corona SDK doesn开发者_如何学Python't support LuaLanes. So it's quite impossible to listen udp message in another thread.
So I'm just thinking if there's any method/trick/workaround in lua to detect and cancel if a function, in this case udp.receive(), is taking too long to respond?
Thanks in advance
Yes.. Coroutines and events.. http://www.lua.org/pil/9.4.html
Fire a timer event that say calls a function every 100msec.. In that function resume a coroutine..
In the coroutine. You can read the incoming data in a loop and yield if not complete.
The example explains this well..
Good luck.. F.
Have you set the upd timeout?
See http://w3.impa.br/~diego/software/luasocket/udp.html at the bottom of the page.
精彩评论