Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Totally right - polling is typically a waste of resources. Until recently, many apps would either keep a socket open and poll every few minutes to keep it alive, or make periodic HTTP calls to a server.</p> <p>Nowadays, <a href="https://developer.android.com/google/gcm/index.html" rel="nofollow">Google Cloud Messaging</a> is used by most apps to push data instead of constantly polling. As you correctly guessed, this is implemented by maintaining a persistent connection with Google's servers. The advantage of this is that it's very efficient for battery life, and that all apps can use this one resource to send push notifications, instead of each app having to poll a different server or create its own persistent connection.</p> <p>The idea is that you send requests to GCM from your server (this can be in response to user activity, etc), which sends it to all of the client's devices. You can either send a message with a small payload (up to 4kb) or a "send-to-sync" message, which tells an app to contact the server (e.g. to sync new data from the server after user changes).</p> <blockquote> <p>here is where I assume the operating system steps in and assumes the role of polling for the appropriate port, and letting the application know using the appropriate event (the application subscribes using the OS API)</p> </blockquote> <p>GCM pushes messages to clients, so there isn't active waiting like you'd see in a simple polling system.</p> <blockquote> <p>how is a message from server to client work exactly? and how does the server know the client's IP at all times?</p> </blockquote> <p>There's no need for servers to know the client IP, as any online android device will typically maintain a connection with GCM. Targeting specific users is done via <a href="http://developer.android.com/google/gcm/notifications.html" rel="nofollow">User Notifications</a>.</p> <p>(Oh, and I realize that your question is more general than just Android, which I have more experience in, but iOS has a similar system in place. Some developers I've met like to use <a href="https://parse.com/tutorials/ios-push-notifications" rel="nofollow">Parse</a> for managing push notifications).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload