socket.receive blocks; Timer event not executed

I am trying to write an app which:

  • Gets GPS data (done)

  • Connects to a TCP server (done)

  • waits for incoming strings from this server (not done right yet)

  • Runs a Timer which every 60 seconds transmits the GPS data to same TCP server using socket.send(Does not work)

Because the socket.receive blocks, the Timer event is not executed.

I am a Delphi Pascal programmer. In Delphi, I would have to set up a separate Thread to be able to write to the TCP server, while at the same time waiting for a blocking Read.

How do I do this in Corona Lua?

I would also really appreciate any example code to do this properly.

Thanks, Bart

http://www.sartrack.co.nz/

Hello Bart,

You can set non-blocking sockets like this:

tcpSocket:settimeout(0) 

One caveat however is there is an internal buffer that can overflow if you try to send too much stuff too fast. Nonblocking IO can fill up this buffer and result in truncated or interleaved messages.

Regards,

M.Y. Developers

Ah yes, that seems to work.

I now use two timers to run both the Receive and Transmit side.

Only thing I can’t seem to find, is how to detect an error (specifially: A Disconnect event).

So that I can start a re-connect when that happens.

How do I do this?

Thanks, Bart

Hello Bart,

You can set non-blocking sockets like this:

tcpSocket:settimeout(0) 

One caveat however is there is an internal buffer that can overflow if you try to send too much stuff too fast. Nonblocking IO can fill up this buffer and result in truncated or interleaved messages.

Regards,

M.Y. Developers

Ah yes, that seems to work.

I now use two timers to run both the Receive and Transmit side.

Only thing I can’t seem to find, is how to detect an error (specifially: A Disconnect event).

So that I can start a re-connect when that happens.

How do I do this?

Thanks, Bart