I mean do they use ping-pong messages to get user connection information? In short, how they know where to send for coming request?
For iOS, these apps use APNS (Apple Push Notification Service).
This is a service provided by Apple that helps applications to alert users when something happens.
In short (and simplified), it works like this
When the app is installed, the user is asked if the app should be allowed to send push messages to the phone.
If the user accepts, the app registers to the APNS server (hosted by Apple) and registers a "device token". This token is a serial number that helps the Apple Server to keep track of the phone.
The app connects to the application server (for example Viber's server) and sends the device token also to this server. The server will connect it to a specific user.
When the user receives a call, the viber server contacts the APNS server, which in turn alerts the user.
The APNS server keeps track of all apps the user has on his/her phone. It will handle notifications for all of them. The connection between the iPhone and the APNS server is built-in to the iOS platform and it happens automatically on a regular basis.
When the APNS server is told by the viber server that something is happening for specific device token, the APNS server will contact that specific phone and send a message to the phone. In this case the user will be told that he/she has an incoming call from viber.
Documentation for APNS can be found here: Local and push notification programming guide
When it comes to Android, there is a equivalent service, C2DM My guess is that these apps are working in a similar way on Android using this service.
If you need a little help getting started with Push, there is a great service called Urban Airship that makes things a lot easier, it support both iOS, Android and other platforms.
EDIT: In the case where the application is already open the connection can either be kept open using a socket connection, or content can be refreshed by polling. It depends on how time critical the application is.
In such applications, users are track based on Android Device Unique ID.
import android.provider.Settings.Secure;
private String android_id = Secure.getString(getContext().getContentResolver(),
Secure.ANDROID_ID);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With