W
W
wickedweasel2013-11-06 11:30:05
iOS
wickedweasel, 2013-11-06 11:30:05

Keep-alive sockets in iOS?

Good afternoon, comrades.

I myself am from the world of server development, but at the moment I am developing, let's say, a socket server for serving mobile applications. The bottom line is this: I want to maintain a connection with the server so that the server can send a message to the client at any time.
And now I was interested in such a topic: what timeouts and connection support intervals are better to set.
At the same time, I would like to consume a minimum battery for servicing a network connection if it is not used to deliver meaningful messages.

Both contexts are considered:
1) The application is running, is in the foreground. How often should you send pings so that the socket is considered alive and any message from the server reaches the client almost instantly? Or is it not needed at all, and TCP keep-alive will be enough?
2) The application is running, but is in the background. We believe that in this case we set the keep alive handler every 10 minutes, as advised by the iOS documentation for VoIP applications . Naturally, such a handler will only be set when we are really interested in receiving messages in the background. In general, I also wanted to know if this is the right approach?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
brainplus, 2013-11-06
@brainplus

2) keep-alive handler can be set for 3 hours if you do not need to wake up more often. You can even assign 100500 hours as the interval between calls to keep alive handler - keep the connection open if your socket is marked to work in the background - this is the task of iOS, you don't need to think about it.
This is my IMHO.

U
usgleb, 2013-11-17
@usgleb

1) I sent keep-alive presense every 45 seconds. This was the back-end requirement that we used. As far as I understand, these presense are needed only for the back end, iOS did not close the socket while the application was running.
2) I started playing a silent track so that the application would work constantly and not die. So it has a higher priority in the system.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question