Running an HTTP Request over WWAN

This thread has been locked by a moderator.

For important background information, read Extra-ordinary Networking before reading this.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"


Running an HTTP Request over WWAN

URLSessionConfiguration has a property, allowsCellularAccess, that controls whether requests in that session are allowed to run over WWAN. However, there’s no opposite of that, a way to force requests to run over WWAN. Some apps need to do this.

IMPORTANT There are good and bad reasons to force a request to run over WWAN. I’ll explain a good reason below, but a bad reason is that you think that using WWAN is better aligned with your user’s networking preferences. Don’t go down that path. Rather, use the constraints mechanism described in Network Interface Techniques to align with the user’s preferences.

So what’s an example of a good reason for this? I once worked with a developer who’d cut a deal with a cellular carrier to offer special benefits to that carrier’s users. Rather than require that the user give the app access to their cellular account, they wanted to run an HTTP request over WWAN to a server that’s only available on the carrier’s network.

If you’re using Network framework, or even BSD Sockets, this isn’t a problem. For information about how to bind a connection to an interface, see Network Interface Techniques. If you’re using URLSession, there’s no obvious way to achieve this goal, but there are two non-obvious approaches you can try:

  • Implement your own HTTP protocol

  • Fun with Multipath TCP!

Regarding the first approach, see the discussion in the HTTP alternatives section of TN3151 Choosing the right networking API.

Regarding the second approach, the basic idea is to set up an HTTP server with Multipath TCP (MPTCP) support on the carrier’s network. If your app issues a request to that server while both Wi-Fi and WWAN are active, the system will try to connect over both interfaces. The Wi-Fi connection will fail but the WWAN connection will succeed, and thus the request runs over WWAN. Neat-o!

For information on how to enable MPTCP with URLSession, see Supporting Multipath TCP.

Up vote post of eskimo
364 views