---
title: CFMessagePort
framework: corefoundation
role: symbol
role_heading: Class
path: corefoundation/cfmessageport
---

# CFMessagePort

## Declaration

```swift
class CFMessagePort
```

## Overview

Overview CFMessagePort objects provide a communications channel that can transmit arbitrary data between multiple threads or processes on the local machine. You create a local message port with CFMessagePortCreateLocal(_:_:_:_:_:) and make it available to other processes by giving it a name, either when you create it or later with CFMessagePortSetName(_:_:). Other processes then connect to it using CFMessagePortCreateRemote(_:_:), specifying the name of the port. To listen for messages, you need to create a run loop source with CFMessagePortCreateRunLoopSource(_:_:_:) and add it to a run loop with CFRunLoopAddSource(_:_:_:). important: If you want to tear down the connection, you must invalidate the port (using CFMessagePortInvalidate(_:)) before releasing the runloop source and the message port object. Your message port’s callback function will be called when a message arrives. To send data, you store the data in a CFData object and call CFMessagePortSendRequest(_:_:_:_:_:_:_:). You can optionally have the function wait for a reply and return the reply in another CFData object. Message ports only support communication on the local machine. For network communication, you have to use a CFSocket object.

## Topics

### Creating a CFMessagePort Object

- [CFMessagePortCreateLocal(_:_:_:_:_:)](corefoundation/cfmessageportcreatelocal(_:_:_:_:_:).md)
- [CFMessagePortCreateRemote(_:_:)](corefoundation/cfmessageportcreateremote(_:_:).md)

### Configuring a CFMessagePort Object

- [CFMessagePortCreateRunLoopSource(_:_:_:)](corefoundation/cfmessageportcreaterunloopsource(_:_:_:).md)
- [CFMessagePortSetInvalidationCallBack(_:_:)](corefoundation/cfmessageportsetinvalidationcallback(_:_:).md)
- [CFMessagePortSetName(_:_:)](corefoundation/cfmessageportsetname(_:_:).md)

### Using a Message Port

- [CFMessagePortInvalidate(_:)](corefoundation/cfmessageportinvalidate(_:).md)
- [CFMessagePortSendRequest(_:_:_:_:_:_:_:)](corefoundation/cfmessageportsendrequest(_:_:_:_:_:_:_:).md)
- [CFMessagePortSetDispatchQueue(_:_:)](corefoundation/cfmessageportsetdispatchqueue(_:_:).md)

### Examining a Message Port

- [CFMessagePortGetContext(_:_:)](corefoundation/cfmessageportgetcontext(_:_:).md)
- [CFMessagePortGetInvalidationCallBack(_:)](corefoundation/cfmessageportgetinvalidationcallback(_:).md)
- [CFMessagePortGetName(_:)](corefoundation/cfmessageportgetname(_:).md)
- [CFMessagePortIsRemote(_:)](corefoundation/cfmessageportisremote(_:).md)
- [CFMessagePortIsValid(_:)](corefoundation/cfmessageportisvalid(_:).md)

### Getting the CFMessagePort Type ID

- [CFMessagePortGetTypeID()](corefoundation/cfmessageportgettypeid().md)

### Callbacks

- [CFMessagePortCallBack](corefoundation/cfmessageportcallback.md)
- [CFMessagePortInvalidationCallBack](corefoundation/cfmessageportinvalidationcallback.md)

### Data Types

- [CFMessagePortContext](corefoundation/cfmessageportcontext.md)

### Constants

- [CFMessagePortSendRequest Error Codes](corefoundation/1561514-cfmessageportsendrequest-error-c.md)

## Relationships

### Conforms To

- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)

## See Also

### Opaque Types

- [CFAllocator](corefoundation/cfallocator.md)
- [CFArray](corefoundation/cfarray.md)
- [CFAttributedString](corefoundation/cfattributedstring.md)
- [CFBag](corefoundation/cfbag.md)
- [CFBinaryHeap](corefoundation/cfbinaryheap.md)
- [CFBitVector](corefoundation/cfbitvector.md)
- [CFBoolean](corefoundation/cfboolean.md)
- [CFBundle](corefoundation/cfbundle.md)
- [CFCalendar](corefoundation/cfcalendar.md)
- [CFCharacterSet](corefoundation/cfcharacterset.md)
- [CFData](corefoundation/cfdata.md)
- [CFDate](corefoundation/cfdate.md)
- [CFDateFormatter](corefoundation/cfdateformatter.md)
- [CFDictionary](corefoundation/cfdictionary.md)
- [CFError](corefoundation/cferror.md)
