Search code examples
iosmacostvoswatchosipados

Is POSIX C networking / BSD socket APIs a supported API for Apple platfroms like iOS, iPadOS, tvOS?


We are writing a networking library that supports communication between endpoints on a proprietary protocol over UDP. We want to build that library not only for Apple Platforms but also other non-Apple platforms (like Windows, Linux, Android etc.) Considering this, one choice we have is to use POSIX C networking / BSD socket APIs.

One thing, which is NOT coming out clearly from Apple documentation is - can we use BSD sockets APIs and it work on most Apple platforms.

They do mention it won't work on watchOS 9 onwards. Link

The BSD sockets API doesn’t work for networking on watchOS under any circumstances. Use Network framework instead.

BUT nowhere they mention that BSD sockets is one of the supported method in their latest documentation. Link.

Some archived documentation does say, it is a supported method. Link. BUT is it still supported, how would one know?.


Solution

  • Yes, it is allowed.

    Please refer to this apple documentation:

    It says:
    Apple platforms have a wide range of networking APIs, spanning many different frameworks:

    • Foundation,
    • Network,
    • BSD Sockets in the System framework,
    • And more

    If you’re working on watchOS, read TN3135: Low-level networking on watchOS to understand its unique constraints.

    Recommendations by Transport Layer protocols:

    1. For both TCP and UDP you have two reasonable options: Network framework using NWConnection (Swift) or nw_connection_t (C-based languages) and BSD Sockets.
    2. Network framework is by far the best choice. BSD Sockets is an acceptable choice if you have compatibility constraints, for example: When writing cross-platform code. Or When using an existing library that’s based on BSD Sockets.