Changes between Version 63 and Version 64 of Getting-Started/iPhone


Ignore:
Timestamp:
May 23, 2014 11:32:57 AM (10 years ago)
Author:
nanang
Comment:

Add info for SIP transport keepalive in background

Legend:

Unmodified
Added
Removed
Modified
  • Getting-Started/iPhone

    v63 v64  
    179179Go to System Preferences > Sound > Sound Effects and then uncheck and recheck "Play user interface sound effects". If it still doesn't work, you can try some other suggestions [http://stackoverflow.com/questions/302399/sound-not-working-in-iphone-simulator here]. 
    180180 
     181=== SIP transport keepalive while in background === #keepalive 
     182 
     183As the process is normally suspended when application is in the background, the worker thread that handles TCP keepalive timer is also suspended. So basically application needs to schedule periodic wakeup to allow the library send TCP keep-alive. Sample code: 
     184{{{ 
     185- (void)keepAlive { 
     186    /* Register this thread if not yet */ 
     187    if (!pj_thread_is_registered()) { 
     188        static pj_thread_desc   thread_desc; 
     189        static pj_thread_t     *thread; 
     190        pj_thread_register("mainthread", thread_desc, &thread); 
     191    } 
     192 
     193    /* Simply sleep for 5s, give the time for library to send transport 
     194     * keepalive packet, and wait for server response if any. Don't sleep 
     195     * too short, to avoid too many wakeups, because when there is any 
     196     * response from server, app will be woken up again (see also #1482). 
     197     */ 
     198    pj_thread_sleep(5000); 
     199} 
     200 
     201- (void)applicationDidEnterBackground:(UIApplication *)application 
     202{ 
     203    /* Send keep alive manually at the beginning of background */ 
     204    pjsip_endpt_send_raw*(...); 
     205 
     206    /* iOS requires that the minimum keep alive interval is 600s */ 
     207    [application setKeepAliveTimeout:600 handler: ^{ 
     208        [self performSelectorOnMainThread:@selector(keepAlive) 
     209              withObject:nil waitUntilDone:YES]; 
     210    }]; 
     211} 
     212}}} 
     213 
     214Make sure that keepalive feature of SIP transport is not disabled, see [http://www.pjsip.org/docs/latest/pjsip/docs/html/group__PJSIP__CONFIG.htm#ga02217f4919a7c575d71eed407be63d04 PJSIP_TCP/TLS_KEEP_ALIVE_INTERVAL] docs, and the keepalive interval is set to less than 600s. 
     215 
     216Alternatively, configuring server to send keepalive ping packet, if possible, and client responds back by sending keepalive pong to the server, so we have two-way traffic. As there is no way to detect incoming ping from server, currently application can just always send pong packet whenever it becomes active (application will be woken up when receiving TCP packet), e.g: send pong packet in UIApplication::applicationDidBecomeActive(). 
     217 
    181218=== List of Issues === 
    182219 
     
    190227 * [http://code.google.com/p/pjsip-iphone-audio-driver/ iPhone Audio Driver] by [http://www.voalte.com/ Voalté] 
    191228 * [http://code.teluu.com/tabikphone/ TabikPhone], an adaptation of Sipphone code from V-Net Corp 
    192