IPCSocket stops receiving data - found a workaround

Hi,

I have a problem using IPCsockets between my main app and a helper app which should play the sounds of the main app.
My system is OS X 10.10 (2.5 GHz Intel Core i7).
I’ve outsourced the the sounds to a helper app since playing them it is too expensive for the main app, especially when multiple sounds are played at once.

So far, there is no problem with connection establishing, and transferring data.
In the helper app, I’ve also have a timer which polls the received data and does specific commands (like playing different sounds).
In the main app, data (e.g. “1” for sound 1) is written into its IPCsocket.
This all runs fine but after some time (just several seconds) (without any data exchange) the helper apps IPCsocket doesn’t seem to get the data in time anymore.
As soon as I switch to the helper app (I print its IPCsocket receiving in a label), it seems to work again and fire all accumulated data since it stopped at once.
After that, sounds are played normally again in the main app until the helper starts again to ‘stop’.

How is it possible that even with a timer the data isn’t received steadily by the helper app and seems to accumulate after some time and then get all at once when I set the helper to focus?

Thanks in advance!

Are you calling Flush after Write? I just started using IPCSockets and always call Flush and haven’t had this problem.

Yes I do call Flush after every new Write command. How frequently do you send data between your sockets?

I write maybe 10 messages a second where each message is a 3MB picture. That runs to the end and then the connection is closed. But in my experiments learning how to use IPCSockets I had apps writing textfields to each other by my sporadic, manual typing, a handful back and forth but several seconds between and the connection held.

The only other difference I see is that I don’t Poll the socket but that shouldn’t be a problem. Hopefully someone with more experience can chime in.

Okay thank you for sharing this info! Yeah, I tried it with and without ‘Poll’.
Maybe the helper app IPCsocket fires its “DataAvailable” too early if it is data available again, so that the method is stoping before its end… I don’t know, simply have to go on experimenting I think :wink:

Another guess is App Nap is causing this, that’s why it all flows when made active again. Try get info on the app and check ‘prevent app nap’.

Thanks Will, I think that really was the problem (since I even use a system toggle fullscreen command in the main app). Sadly there is no way to prevent the app from doing this nap…

But, I think that I’ve found a workaround:
Even if the main app has no actual sound to play, it always (50ms) sends a ‘heartbeat command’, which lets the helper app play a sound at volume 0, just to keep it ‘doing something’. This isn’t too expensive and it seems like the helper app isn’t ‘napping’ that way. Nevertheless, I have to do further tests with actual gameplay.

https://forum.xojo.com/7802-prevent-app-nap
https://forum.xojo.com/6207-disable-app-nap-for-your-application

And

Thanks Norman, I’ll have a look at these!