Contents

CFSocket

Declaration

class CFSocket

Overview

A CFSocket is a communications channel implemented with a BSD socket.

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>

CFSocket can be created from scratch with CFSocketCreate(_:_:_:_:_:_:_:) and CFSocketCreateWithSocketSignature(_:_:_:_:_:). CFSocket objects can also be created to wrap an existing BSD socket by calling CFSocketCreateWithNative(_:_:_:_:_:). Finally, you can create a CFSocket and connect simultaneously to a remote host by calling CFSocketCreateConnectedToSocketSignature(_:_:_:_:_:_:).

To listen for messages, you need to create a run loop source with CFSocketCreateRunLoopSource(_:_:_:) and add it to a run loop with CFRunLoopAddSource(_:_:_:). You can select the types of socket activities, such as connection attempts or data arrivals, that cause the source to fire and invoke your CFSocket’s callback function. To send data, you store the data in a CFData and call CFSocketSendData(_:_:_:_:).

Unlike Mach and message ports, sockets support communication over a network.

Topics

Creating Sockets

Configuring Sockets

Using Sockets

Callbacks

Data Types

Constants

See Also

Related Documentation

  • Threading Programming Guide
  • CFNetwork Programming Guide

Opaque Types