Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to keep Websocket alive in background iOS

I am creating a VOIP application and also using a SocketRocket library to manage my Websockets and pull data from it. But my main problem is when I click on (IOS) Home button so my websocket disconnects after one minute. I have read Apple's documentation for developing VOIP application from the link below

https://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html

I am also setting UIBackgroundModes in plist for VOIP and Audio, but when I resume my application so my websocket state is closed although I am not releasing websocket Object.

_webSocket.readyState = 3    //  It identifies that my websocket is close.

Now for restablishing a connection with Websocket so I need to call again websocket open and create another instance of Websocket object after releasing previously.

On closing of websocket my SIP registeration from my server also disconnects and I need to reconnect to my SIP again.

How can I prevent my websocket to get close and how can I make setKeepAliveTimeout:handler: useful to fix my problem.

Library use to establish Websocket is as below

https://github.com/square/SocketRocket

like image 983
user366584 Avatar asked Jun 02 '13 13:06

user366584


1 Answers

Try adding the following two lines in SRWebSocket _initializeStreams

// Setup connections to be VOIP connections
CFReadStreamSetProperty(readStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);
CFWriteStreamSetProperty(writeStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);
like image 74
Nailer Avatar answered Nov 15 '22 10:11

Nailer