### Start a TCP Server Source: https://context7.com/rsms/peertalk/llms.txt Binds and listens on a local IPv4 port. Each accepted connection triggers a delegate method. ```APIDOC ## PTChannel -listenOnPort:IPv4Address:callback: ### Description Binds and listens on a local IPv4 port. Each accepted connection triggers the delegate method `ioFrameChannel:didAcceptConnection:fromAddress:`, where the new peer's `PTChannel` and `PTAddress` are provided. Typically used on the iOS side to accept a connection from the macOS host. ### Method `listenOnPort:IPv4Address:callback:` ### Parameters - `port` (in_port_t) - The local IPv4 port to listen on. - `IPv4Address` (IPv4Address) - The IPv4 address to bind to (e.g., `INADDR_LOOPBACK` for 127.0.0.1). - `callback` (^(NSError *error)) - A callback block executed upon completion, receiving an `NSError` if an error occurred. ### Request Example ```objc static const in_port_t kPort = 2345; PTChannel *serverChannel = [PTChannel channelWithDelegate:self]; [serverChannel listenOnPort:kPort IPv4Address:INADDR_LOOPBACK // 127.0.0.1 — loopback only callback:^(NSError *error) { if (error) { NSLog(@"Failed to listen on 127.0.0.1:%d — %@", kPort, error); return; } NSLog(@"Listening on 127.0.0.1:%d", kPort); }]; ``` ### Delegate Method - `ioFrameChannel:(PTChannel *)channel didAcceptConnection:(PTChannel *)peer fromAddress:(PTAddress *)address` - Description: Called when a new connection is accepted. - Parameters: - `channel` (PTChannel *) - The server channel. - `peer` (PTChannel *) - The channel for the new peer connection. - `address` (PTAddress *) - The address of the connecting peer. ``` -------------------------------- ### Start TCP Server with PTChannel Source: https://context7.com/rsms/peertalk/llms.txt Binds and listens on a local IPv4 port. Each accepted connection triggers a delegate method. Typically used on the iOS side to accept a connection from the macOS host. ```objc static const in_port_t kPort = 2345; PTChannel *serverChannel = [PTChannel channelWithDelegate:self]; [serverChannel listenOnPort:kPort IPv4Address:INADDR_LOOPBACK // 127.0.0.1 — loopback only callback:^(NSError *error) { if (error) { NSLog(@"Failed to listen on 127.0.0.1:%d — %@", kPort, error); return; } NSLog(@"Listening on 127.0.0.1:%d", kPort); }]; // PTChannelDelegate (on accepting side) - (void)ioFrameChannel:(PTChannel *)channel didAcceptConnection:(PTChannel *)peer fromAddress:(PTAddress *)address { NSLog(@"Accepted connection from %@:%ld", address.name, (long)address.port); self.peerChannel = peer; } ``` -------------------------------- ### Observe PTUSBDeviceDidAttachNotification in Swift Source: https://context7.com/rsms/peertalk/llms.txt This Swift example demonstrates how to observe USB device attachment notifications and extract device information such as ID and serial number from the user info dictionary. ```swift // Swift observation example NotificationCenter.default.addObserver( forName: .deviceDidAttach, object: PTUSBHub.shared(), queue: nil ) { note in let deviceID = note.userInfo?[PTUSBHubNotificationKey.deviceID] as? NSNumber let props = note.userInfo?[PTUSBHubNotificationKey.properties] as? [String: Any] let serial = props?["SerialNumber"] as? String ?? "?" print("Attached: device \(deviceID?.intValue ?? -1), serial \(serial)") } ``` -------------------------------- ### Showdown Markdown Converter - Initialization Source: https://github.com/rsms/peertalk/blob/master/index.html Initializes the Showdown converter object, setting up properties like `anchorPrefix` and `anchorLinks`. The `makeHtml` method is the main entry point for converting Markdown to HTML. ```javascript var Showdown = {converter:function() { function n(a, b) { var b = o(b), c = "'; c += p.anchorLinks ? '' + b + "" : b }else { c += ">" + b } c += ""; return l(c) } var i, j, m, q = 0, p = this; this.anchorPrefix = ""; this.anchorLinks = true; this.makeHtml = function(a) { i = []; j = []; m = []; a = a.replace(/~/g, "~T"); a = a.replace(/\$/g, "~D"); a = a.replace(/\r\n/g, "\n"); a = a.replace(/\r/g, "\n"); a = w("\n\n" + a + "\n\n"); a = a.replace(/^\s\[ \t\]+$/mg, ""); a = x(a); a = E(a); a = r(a); a = y(a); a = a.replace(/~D/g, "$"); a = a.replace(/~T/g, "~"); a = a.replace(/--/g, "—"); return a = a.replace(/(\[a-z0-9\_\-+=.]{1,})@(\[a-z0-9\-\]{1,}(\.([a-z0-9\-\]{1,}){1,}))/ig, function(a) { return"" + a + "" }) }; var E = function(a) { return a = a.replace(/^\s\[ \t\]{0,3}\s*\[(.+)\]:\s*\n?\s*\[ \t\]\*?\s*\n?\s*(?:(\n\s*)\["(](.+?)["]\]\s*\])?(?:\n+|\Z)/gm, function(a, c, d, e, g) { c = c.toLowerCase(); i[c] = z(d); if(e) { return e + g }else { g && (j[c] = g.replace(/ ``` -------------------------------- ### Create a PTChannel Instance Source: https://context7.com/rsms/peertalk/llms.txt Create a PTChannel instance with a delegate for callback delivery. Optionally, supply a custom PTProtocol instance tied to a specific GCD queue; otherwise, the shared protocol for the main queue is used. ```objc // Objective-C — convenience constructor PTChannel *channel = [PTChannel channelWithDelegate:self]; ``` ```objc // Objective-C — explicit protocol on a background queue dispatch_queue_t ioQueue = dispatch_queue_create("com.example.peertalk", DISPATCH_QUEUE_SERIAL); PTProtocol *proto = [[PTProtocol alloc] initWithDispatchQueue:ioQueue]; PTChannel *channel = [[PTChannel alloc] initWithProtocol:proto delegate:self]; ``` ```swift // Swift let channel = PTChannel(protocol: nil, delegate: self) ``` -------------------------------- ### Creating a PTChannel Source: https://context7.com/rsms/peertalk/llms.txt This section details how to create a `PTChannel` object, which is the primary high-level object for managing communication channels. It explains how to initialize it with a delegate and optionally with a custom `PTProtocol` instance. ```APIDOC ## `PTChannel` `+channelWithDelegate:` / `-initWithProtocol:delegate:` ### Description `PTChannel` is the primary high-level object for managing communication channels. Create a `PTChannel` instance with a delegate to receive callback deliveries. Optionally, you can supply a custom `PTProtocol` instance tied to a specific GCD queue; otherwise, the shared protocol for the main queue is used automatically. ### Methods - `+channelWithDelegate:(id)delegate`: A convenience constructor for creating a `PTChannel` with the default protocol on the main queue. - `-initWithProtocol:(PTProtocol *)protocol delegate:(id)delegate`: Initializes a `PTChannel` with a specified `PTProtocol` instance and a delegate. ### Parameters - `delegate` (id): An object conforming to the `PTChannelDelegate` protocol, responsible for handling channel events. - `protocol` (PTProtocol *): An optional `PTProtocol` instance to use for framing and unframing messages. If `nil`, the default shared protocol is used. ### Code Example (Objective-C) ```objc // Objective-C — convenience constructor PTChannel *channel = [PTChannel channelWithDelegate:self]; // Objective-C — explicit protocol on a background queue dispatch_queue_t ioQueue = dispatch_queue_create("com.example.peertalk", DISPATCH_QUEUE_SERIAL); PTProtocol *proto = [[PTProtocol alloc] initWithDispatchQueue:ioQueue]; PTChannel *channel = [[PTChannel alloc] initWithProtocol:proto delegate:self]; ``` ### Code Example (Swift) ```swift // Swift let channel = PTChannel(protocol: nil, delegate: self) ``` ``` -------------------------------- ### Load and Render Markdown Content Source: https://github.com/rsms/peertalk/blob/master/index.html Asynchronously loads README.md, converts it to HTML using Showdown.js, and injects it into the DOM. It also handles specific replacements for notes and WebKit compatibility. ```javascript var content = document.getElementById('content'); // Synchronous request so that back/fwd in browsers retain scroll position, etc $.ajax({ async: false, url: 'README.md?'+gFetchTS, error: function (a,b,c) { console.error('Failed to load content:', a,b,c); }, success: function (body) { body = body.replace(/> Note: UILayer only works in WebKit-based environments.+/, 'NOTE_WEBKIT_COMPAT'); var html = (new Showdown.converter()).makeHtml(body); html = html.replace(/]+>.+<\/h1>/, ''); html = html.replace(/

[\r\n.]*NOTE_WEBKIT_COMPAT[\r\n.]*<\/p>/m, '

'); content.innerHTML = html; if (typeof content.querySelectorAll === 'function') { Array.prototype.slice.call(content.querySelectorAll('h3 > a')).forEach(function (el) { if (el.innerHTML === el.innerText) el.innerHTML = el.innerText.replace(/^layer\./, 'layer.'); }); } } }); ``` -------------------------------- ### PTChannelDelegate: Server Accept Connection Source: https://context7.com/rsms/peertalk/llms.txt Server-only delegate method called when a listening channel accepts a new client connection. It manages the accepted peer channel, potentially dropping existing connections if a FIFO policy is enforced. ```objc // Server-only: called when a listening channel accepts a new client - (void)ioFrameChannel:(PTChannel *)channel didAcceptConnection:(PTChannel *)peer fromAddress:(PTAddress *)address { [self.peerChannel cancel]; // drop any existing peer (FIFO policy) self.peerChannel = peer; peer.userInfo = address; NSLog(@"New connection from %@", address); } ``` -------------------------------- ### Initialize Date for Fetching Source: https://github.com/rsms/peertalk/blob/master/index.html Initializes a global variable `gFetchTS` with the current year, month, and day, formatted as a string. This is likely used for timestamping or caching purposes. ```javascript window.gFetchTS = new Date; gFetchTS = gFetchTS.getFullYear()+'-'+gFetchTS.getMonth()+'-'+gFetchTS.getDate()+'-'+gFetchTS.getHours(); ``` -------------------------------- ### Connect to a USB-Bridged TCP Channel Source: https://context7.com/rsms/peertalk/llms.txt This method establishes a connection to a TCP port on a USB-attached device by tunneling through `usbmuxd`. It provides callbacks for connection success and failure, as well as for when the channel is closed. ```APIDOC ## `PTUSBHub` `-connectToDevice:port:onStart:onEnd:` ### Description Connects to a TCP port running on a USB-attached device by tunneling through `usbmuxd`. The `onStart` block is called upon successful connection, providing a `dispatch_io_t` stream channel. The `onEnd` block is called when the channel is later closed. ### Parameters - `deviceID` (NSNumber): The ID of the USB device to connect to. - `port` (int): The TCP port number on the device to connect to. - `onStart` (^(NSError *error, dispatch_io_t channel)): A block that is called when the connection attempt completes. It receives an `NSError` if the connection fails, or a `dispatch_io_t` channel if successful. - `onEnd` (^(NSError *error)): A block that is called when the channel is closed. It receives an `NSError` if the closure was due to an error. ### Error Handling - `PTUSBHubErrorDomain`: Custom error domain for `PTUSBHub` errors. - `PTUSBHubErrorBadDevice`: Indicates an unknown or invalid device. - `PTUSBHubErrorConnectionRefused`: Indicates that the connection was refused by the device. ### Request Example (Objective-C) ```objc NSNumber *deviceID = @(3); // obtained from PTUSBDeviceDidAttachNotification int port = 2345; // must match the listening port on the iOS side [[PTUSBHub sharedHub] connectToDevice:deviceID port:port onStart:^(NSError *error, dispatch_io_t channel) { if (error) { if (error.domain == PTUSBHubErrorDomain) { switch ((PTUSBHubError)error.code) { case PTUSBHubErrorBadDevice: NSLog(@"Unknown device"); break; case PTUSBHubErrorConnectionRefused: NSLog(@"Connection refused"); break; } } else { NSLog(@"Connect failed: %@", error); } return; } // 'channel' is a plain dispatch_io_t — hand it to PTChannel or use it directly NSLog(@"USB channel open, fd=%d", dispatch_io_get_descriptor(channel)); } onEnd:^(NSError *error) { NSLog(@"USB channel closed: %@", error ?: @"(clean)"); }]; ``` ``` -------------------------------- ### Connect Over TCP/IP with PTChannel Source: https://context7.com/rsms/peertalk/llms.txt Connects to a TCP endpoint identified by an IPv4 address and port. Use this for loopback or LAN connections when USB is unavailable. Schedules a retry if the connection is refused or times out. ```objc PTChannel *channel = [PTChannel channelWithDelegate:self]; // Connect to 127.0.0.1:2345 [channel connectToPort:2345 IPv4Address:INADDR_LOOPBACK // already host byte order callback:^(NSError *error, PTAddress *address) { if (error) { if (error.domain == NSPOSIXErrorDomain && (error.code == ECONNREFUSED || error.code == ETIMEDOUT)) { // Expected when peer is not ready — schedule retry } else { NSLog(@"TCP connect error: %@", error); } return; } NSLog(@"Connected to %@", address); // prints "127.0.0.1:2345" self.connectedChannel = channel; channel.userInfo = address; }]; ``` -------------------------------- ### Connect Over USB Source: https://context7.com/rsms/peertalk/llms.txt Opens a PTChannel to a TCP port on a USB-attached device using `PTUSBHub` as the transport. ```APIDOC ## PTChannel -connectToPort:overUSBHub:deviceID:callback: ### Description Opens a PTChannel to a TCP port on a USB-attached device using `PTUSBHub` as the transport. This is the primary entry point for the macOS side to reach an iOS app listening on a local port. ### Method `connectToPort:overUSBHub:deviceID:callback:` ### Parameters - `port` (NSInteger) - The TCP port to connect to on the remote device. - `overUSBHub` (PTUSBHub *) - The `PTUSBHub` instance to use for transport. - `deviceID` (NSNumber *) - The unique identifier for the USB device. - `callback` (^(NSError *error)) - A callback block executed upon completion, receiving an `NSError` if an error occurred. ### Request Example ```objc // Called after receiving PTUSBDeviceDidAttachNotification - (void)connectToUSBDevice:(NSNumber *)deviceID { PTChannel *channel = [PTChannel channelWithDelegate:self]; channel.userInfo = deviceID; [channel connectToPort:2345 overUSBHub:PTUSBHub.sharedHub deviceID:deviceID callback:^(NSError *error) { if (error) { if (error.domain == PTUSBHubErrorDomain && error.code == PTUSBHubErrorConnectionRefused) { // iOS app not yet ready — retry after delay [self performSelector:@selector(retryConnect) withObject:nil afterDelay:1.0]; } else { NSLog(@"USB connect error: %@", error); } return; } self.connectedChannel = channel; NSLog(@"Connected to device %@ over USB", deviceID); }]; } ``` ``` -------------------------------- ### Pretty Print Code Snippets Source: https://github.com/rsms/peertalk/blob/master/index.html Applies syntax highlighting to code blocks within
 tags. It adds the 'prettyprint lang-mv' class to elements containing code, excluding those marked as 'plain-text'.

```javascript
# Code pretty printer
v = document.getElementsByTagName 'pre'
for (i=0,L=v.length; i < L; ++i) {
    n = v.item i
    a = n.getAttribute('class') || ''
    if (a.indexOf('plain-text') != -1) continue
    if (n.firstChild && n.firstChild.nodeName == 'CODE') n.setAttribute 'class', a+' prettyprint lang-mv'
}
script = document.createElement 'script'
script.async = true
script.src = "examples/prettify.js"
document.getElementsByTagName('head')[0].appendChild script
```

--------------------------------

### Showdown Markdown Converter - Inline Formatting

Source: https://github.com/rsms/peertalk/blob/master/index.html

Handles inline Markdown formatting such as bold and italic text. It converts double asterisks or underscores to `` tags and single asterisks or underscores to `` tags.

```javascript
a = K(a); a = a = z(a); a = a.replace(/(\\\*\\*|\_\_)(?=\\S)([^\\r\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\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\\\\\\\\\\\\\\"
```

--------------------------------

### Terminate PTChannel Gracefully or Abruptly

Source: https://context7.com/rsms/peertalk/llms.txt

Use `close` for a hard stop, immediately aborting all pending I/O. Use `cancel` for a graceful stop, allowing queued writes and reads to complete before tearing down the channel.

```objc
// Hard close — use when the remote device detached or an unrecoverable error occurred
- (void)didDisconnectFromDevice:(NSNumber *)deviceID {
    if ([self.connectedChannel.userInfo isEqual:deviceID]) {
        [self.connectedChannel close];   // immediate abort
        self.connectedChannel = nil;
    }
}

// Graceful cancel — use for a clean application-initiated disconnect
- (IBAction)disconnectButtonTapped:(id)sender {
    [self.peerChannel cancel];   // flush pending writes, then close
    // delegate's channelDidEnd fires after I/O drains
}
```

--------------------------------

### PTChannel -close and -cancel

Source: https://context7.com/rsms/peertalk/llms.txt

Methods for terminating a PTChannel. `-close` performs a hard stop, immediately aborting all pending I/O, while `-cancel` performs a graceful stop, allowing queued writes and reads to complete before tearing down the channel.

```APIDOC
## PTChannel `-close` and `-cancel` — Terminating a Channel

`close` performs a hard stop — all pending I/O is immediately aborted. `cancel` performs a graceful stop — queued writes and reads are allowed to complete before the channel tears down. Both cause `ioFrameChannel:didEndWithError:` to fire on the delegate.

```objc
// Hard close — use when the remote device detached or an unrecoverable error occurred
- (void)didDisconnectFromDevice:(NSNumber *)deviceID {
    if ([self.connectedChannel.userInfo isEqual:deviceID]) {
        [self.connectedChannel close];   // immediate abort
        self.connectedChannel = nil;
    }
}

// Graceful cancel — use for a clean application-initiated disconnect
- (IBAction)disconnectButtonTapped:(id)sender {
    [self.peerChannel cancel];   // flush pending writes, then close
    // delegate's channelDidEnd fires after I/O drains
}
```
```

--------------------------------

### Showdown Markdown Converter - Link and Image Parsing

Source: https://github.com/rsms/peertalk/blob/master/index.html

Parses Markdown-style links and images, including those with titles. It handles both inline and reference-style links, converting them into HTML anchor tags.

```javascript
var o = function(a) { var e; var d; var c; var b; a = I(a); a = a = J(a); a = a.replace(/\\(\\)/g, s); a = (b = a = a.replace(/\\(\[\`\*\_\{\}\[\]\(\)>#\+\-.!\s\])/g, s), a = b); a = a.replace(/(!\s*\[(.
*?)\]\s*\]\s*(?:\n\s*)?\[(.
*?)\])()()()()/g, B); a = (c = a = a.replace(/(!\s*\[(.
*?)\]\s*\(\s*\[ \t\n]*()?\s*(?:(\["'\])(.
*?)\6\s*)?\))/g, B), a = c); a = a.replace(/(\s*\[((?:\s*\[\[^\\\]\]\*\s*\]|[^\\\[\\\]\])\*)\s*\]\s*(?:\n\s*)?\[(.
*?)\])()()()()/g, t); a = a.replace(/(\s*\[((?:\s*\[\[^\\\]\]\*\s*\]|[^\\\[\\\]\])\*)\s*\]\s*\(\s*\[ \t\n]*()?\s*(?:(\["'\])(.
*?)\6\s*)?\))/g, t); d = a = a.replace(/(\s*\[([^\\\[\\\]\]+)\s*\])()()()()()/g, t), a = d; a = K(a); a = a = z(a); a = a.replace(/(\\*\*|\_\_)(?=\S)([^\r]*?\S[\*\_]*)\1/g, "$2"); a = a.replace(/(\w)\_(\w)/g, "$1~E95E$2"); e = a = a.replace(/(\*|\_)(?=\S)([^\r]*?\S)\1/g, "$2"), a = e; return a.replace(/ +\n/g, " 
\n") }, J = function(a) { return a = a.replace(/(<\/?\s*\w+[^>]*>|)/gi, function(a) { a = a.replace(/(.)<\/?code>(?=.)/g, "$1`"); return k(a, "\\`\*_") }) }, t = function(a, b, c, d, e, g, h, f) { f == void 0 && (f = ""); a = d.toLowerCase(); if(e == "") { if(a == "" && (a = c.toLowerCase().replace(/ ?\n/g, " ")), i[a] != void 0) { e = i[a], j[a] != void 0 && (f = j[a]) }else { if(b.search(/\(\s*\)$/m) > -1) { e = "" }else { return b } } } e = k(e, "*_"); b = '