I have an iOS application that uses TCP connection to connect to a host server using objective C.
I want my app to send keepalive to the host.
I had initially tried creating a timer event that sends keepalive packet. But this stops when the app is minimized. I could see that the socket can be configured to send TCP keepalive using SO_KEEPALIVE in setsocketopt() method.
1. Will this help my app send keepalive even when it is minimized.(The app is configured as VOIP to run in background)
2. How do I enable keepalive and set the delay.
This is what I tried. I am using CFStream for read write. Once the stream is open I have used the below lines of code from similar to what was given in
NSStream TCP Keep-alive iOS
CFSocketNativeHandle nativeHandle;
CFDataRef nativeProperty = CFReadStreamCopyProperty(readStream, kCFStreamPropertySocketNativeHandle);
CFDataGetBytes(nativeProperty, CFRangeMake(0, CFDataGetLength(nativeProperty)), (UInt8 *)&native);
CFRelease(nativeProperty);
int delay=5;
setsockopt(nativeHandle, SOL_SOCKET, SO_KEEPALIVE,&delay, sizeof(delay));
But I could not see any keepalive packet being sent. I am trying to see the keepalive using wireshark. The packets transferred is similar to the packets without the above changes. When i put the delay as 5, I am expecting there to be a 5 sec delay between the keepalives. I hope I am right here.
Any help is much appreciated.