6

I have a decent understanding of networking, but this question popped up in my head randomly and I can't figure it out. For example, if I have an iPhone that is used on a 3G network but is also connected to my home wifi throughout the day, how does an application know whether to send data (whether it be a push notification or something else) to my phone via my cellular IP, or my Wifi IP address? Wouldn't both the cellular network and my home network associate my phone with themselves?

11

In this scenario, your phone has at least two network interfaces: WLAN and 3G. Each interface has his own IP address and mask. They usually install as two routes on the phones routing table, the locally connected network and a default gateway.

Let's see a simplified example:

Interface: Wifi IP/mask: 192.168.10.10 255.255.255.0 Default gateway: 192.168.10.1 (your home router)

Interface: 3G IP/mask: 10.10.10.10 255.255.255.0 Default gateway: 10.10.10.1 (your next hop to ISP)

Resulting routing table:

Destination Interface Metric

192.168.10.0/24 Wifi 0

0.0.0.0/0 Wifi 20

10.10.10.0 3G 0

0.0.0.0/0 3G 30

So, what happens when your phone wants to send a packet? It checks the destination IP address vs its own routing table and decides which interface to send it to.

  • If you send a packet to 192.168.10.49 it matchs first line and sends it through the Wifi interface.
  • If you send a packet to 10.10.10.50 it matches the third line and sends it through the 3G interface.
  • If you send a a packet to 8.8.8.8 (Google DNS) there are two matches. Which of the two lines has precedence? The one with the lowest metric. In this case it's the second line and your packet to internet will go through the Wifi interface.

In personal devices, this metric is automatic. Your iphone is smart enough to set a lower metric to Wifi.

  • So does the same apply for someone who is trying to send a packet to my phone? If there are two possible routes to take to my device (3G and Wifi), how does it decide? @KorXo – raisedandglazed Sep 24 '14 at 15:49
  • Same logic applies in the source. Your interfaces 3G and Wifi has a unique public IP address reachable throught internet. Each interface has ONE address. If I want to send you a packet, I set my destination IP to 80.0.0.1 (your public Wifi IP) or to 90.0.01 (your 3G public IP). I will send this packet throught my deault gateway (my ISP) and it will reach your public IP. – KorXo Sep 24 '14 at 16:21
5

The other answer deals well with how the outbound traffic from your device decides which network connection to use. However it seems your question is asking more about how data inbound to your phone (such as push notifications) decides which network to use.

There are a number of ways this is done, but if it is truly a service that works on both WiFi and cellular, then odds are it periodically "phones home" or establishes and maintains a connection to a server.

When the device/app is checking in or "phoning home," it can collect any messages that are stored for it. In this case, it works much like email and all return traffic from the server will go back to whichever IP address was used to send the request.

Another option is that the device/app creates a connection to the server and keeps it open so that the server can use it to immediately push the notification to the client whenever it receives one. If your device connects/disconnects, the device/app will re-establish the connection to the server. Again, since the device/app will originate this traffic, all return traffic will go to the source IP whether that is on your WiFi network or your cellular network.

0

There's only one default route active, so if you have both enable, it will choose one. For example, if both are reachable, then use wifi, if wifi is unreachable use 3G. The routes are basically balanced with a preference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.