Is it possible to activate TCP keepalive on Apple iOS devices

前端 未结 2 1272
一生所求
一生所求 2020-12-08 12:25

Apple device === Router === WiFi module

Apple device(iPhone) is connecting to WiFi module port 2000 with TCP connection. I want to activate TCP keepalive packet send

2条回答
  •  心在旅途
    2020-12-08 13:07

    see: http://en.wikipedia.org/wiki/Keepalive#TCP_keepalive

    Usually, keepalive time (net.inet.tcp.keepidle) is 7200sec by default. I don't know that is true in iOS or not, but "no less than 2 hours" is clearly required by RFC 1122.

    This interval MUST be configurable and MUST default to no less than two hours.

    So, how could you configure it in your application? try:

    #import 
    #import 
    #import 
    #import 
    
    int on = 1;
    int delay = 120;
    setsockopt(socket_handle, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on));
    setsockopt(socket_handle, IPPROTO_TCP, TCP_KEEPALIVE, &delay, sizeof(delay));
    

    see man tcp.

    I confirmed this works on iOS Simulator (iPhone 5s / iOS 8.0).

提交回复
热议问题