-For TCP, liblinphone automatically configures SIP socket for voip (I.E kCFStreamNetworkServiceType set to kCFStreamNetworkServiceTypeVoIP). <br>
-In the event that an application really wants to use UDP, it is the responsability of application to set this property to the UDP SIP socket before entering in background. It can access the SIP socket from method #linphone_core_get_sip_socket(). Note this property is only settable on a connected socket. As liblinphone UDP sockets are not connected, application willing to enable UDP background mode must first connect the UDP sip socket before configuring the voip mode. Pseudo code below shows the different steps:
-\code
- //get sip socket
- CFReadStreamRef mReadStream
- int sipsock = linphone_core_get_sip_socket(theLinphoneCore);
- //get address port of the sip proxy in order to connect the udp socket to this proxy
- const char *port;
- addr=linphone_address_new(linphone_proxy_config_get_addr(proxyCfg));
- memset(&hints,0,sizeof(hints));
- hints.ai_family=linphone_core_ipv6_enabled(theLinphoneCore) ? AF_INET6 : AF_INET;
- port=linphone_address_get_port(addr);
- if (port==NULL) port="5060";
- err=getaddrinfo(linphone_address_get_domain(addr),port,&hints,&res);
- if (err!=0){
- ms_error("getaddrinfo() failed for %s: %s",linphone_address_get_domain(addr),gai_strerror(err));
- linphone_address_destroy(addr);
- return;
- }
- //connect the udp socket
- err=connect(sipsock,res->ai_addr,res->ai_addrlen);
- if (err==-1){
- ms_error("Connect failed: %s",strerror(errno));
- }
- freeaddrinfo(res);
- //create CFRead stream from the sip socket id
- CFStreamCreatePairWithSocket(NULL, (CFSocketNativeHandle)sipsock, &mReadStream,nil);
- //configure for persistante connection
- if (!CFReadStreamSetProperty(mReadStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP)) {
- ms_error("cannot set service type to voip for read stream");
- }
- if (!CFReadStreamOpen(mReadStream)) {
- ms_error("cannot open read stream");
- }
-
-\endcode
-<br> Note this operation has to be performed every time the application enters in background mode.
-<br> Anyway, for battery saving and interoperability with NAT routers reasons, <b>UDP background mode is not recomended</b>.<br>
-The choice between UDP and TCP transport for sip can be configured with linphone_core_set_sip_transports().