1

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'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

astk
  • 225
  • 2
  • 7

2 Answers2

3

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.

Frank
  • 301
  • 1
  • 11
2

Have you set the upd timeout?

See http://w3.impa.br/~diego/software/luasocket/udp.html at the bottom of the page.

Jane T
  • 2,081
  • 2
  • 17
  • 23