Sending a continuous ping to server in app

Hi, I am working on an app that is supposed to connect to, and ping a server via TCP connection on clicking a button. I have put my server communication inside a coroutine however when I click on the button and the socket is open, the app is frozen and I cant press any other buttons. Also, once the socket is closed on server side, after opening it once - I can’t reopen the socket by pressing the button if in coroutine but if its on the main thread I can do so. Are coroutines the best approach for multithreaded or is there a better approach to send and receive TCP data using Corona Labs - I have made an identical app in Android Studio/Java and have had no problems with multithreading. Please help. Thanks!

Not sure exactly where the problem is without looking at the code, but this by clear a few things out:

Basically your network stuff should be in a “pulsing” loop.

Just some quick notes.

  1. I’d avoid using coroutines. Instead I’d set up networking event listeners combined with a timer or an enterFrame listener depending on what you need to architect.

  2. Corona/Solar2D is not multi-threaded.

  3. Coroutines aren’t threads. Similar, but not the same. Thus, if you don’t suspend the coroutine, it will run forever and block the rest of your game code. Since you already need to use events to wake the suspended coroutine, I’d simply avoid them entirely and use pure events and listeners.