Which module should i import when i using CFSocket?

Hi all,

Which module should i import when i using CFSocket in swift?


I found CFSocket documentation https://developer.apple.com/documentation/corefoundation/cfsocket-rg7 :

For most uses of this API, you will need to include three headers:


#import <CoreFoundation/CoreFoundation.h> #include <sys/socket.h> #include <netinet/in.h>

But when i paste this line to Xcode, there's 5 Errors!!!

Am i missing something? What's the correct module?

Replies

What are you using

CFSocket
for? It’s probably not the droid you’re looking for. Specifically:
  • If you’re looking to make outgoing TCP connections, you should use

    NSStream
  • If you’re listening for incoming TCP connections, use

    NSNetService
    for the listening part and
    NSStream
    for handling the connection
  • If you’re looking to do low-level stuff, like UDP, it’s best to use BSD Sockets, employing dispatch if you need async support

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"