How to activate a cellular radio station in iOS, since bsd sockets do not automatically activate it

I intend to write a cross-platform library in C that I will need to create a network. I saw that iOS supports sockets, but the Apple developer site warns about using POSIX sockets:

On iOS, the POSIX network is discouraged because it does not activate cellular radio or VPN on demand. Thus, as a rule, you should separate the network code from any common data processing functions and rewrite the network code using a higher-level API.

However, this also suggests that POSIX sockets are a good option for something cross-platform. Since POSIX sockets do not automatically activate a cellular radio station, do I need to do it myself? Is there a better way to do this than just open a connection to a higher level api and close the connection before hand?

+7
ios iphone networking sockets
source share
2 answers

tried to do the same, and although documents say that the lower-level API does not activate cellular radio and VPN on demand, this is not entirely true for TCP connections.

In the case of UDP, this is true and your UDP packets are not sent most of the time. To solve this problem, simply open the listening socket for TCP using the lower level API and this will activate cellular radio or VPN on demand and close the socket as soon as you are done.

For TCP, you can use low-level APIs for server-side code on iOS devices, and this will activate cellular radio or VPN on demand, but for client code on iOS devices, it is preferable to use the higher-level APIs that were provided. In any case, the radio is active, and you do not need to worry that packets are not being sent.

By the way, this is what I'm doing right now.

+5
source share
0
source share

All Articles