One Logo Pool Ball
Network · IOS API REFERENCE

NWProtocolFramer.Instance

class · iOS 13.0+ · SDK 27.1

final class Instance

NWProtocolFramer.Instance is an object that a custom framer protocol interacts with in order to drive connection state, parse input and output, and deliver and write data.

Members (18)

method · iOS 13.0+

markFailed

TypeScript
markFailed(error?: (NWError) | null): void
Swift declaration
final func markFailed(error: NWError?)

Mark the connection associated with the framer instance as failed (see NWConnection.State.failed).

get · iOS 13.0+

parameters

TypeScript
get parameters(): (NWParameters) | null
Swift declaration
final var parameters: NWParameters? { get }

The parameters for the framer's connection

method · iOS 13.0+

writeOutput

TypeScript
writeOutputData(data: ArrayBuffer): void
Swift declaration
final func writeOutput(data: Data)

Write arbitrary bytes as part of an outbound message. This is intended to be used for adding headers around application data, or writing any other data that is generated or transformed by the protocol instance. It does not pass along data directly from the application. This function may be called as part of any framer callback, not just handleOutput. - Parameter data: Arbitrary data to write on the connection.

method · iOS 13.0+

writeOutput

TypeScript
writeOutputData25578(data: ArrayBuffer): void
Swift declaration
final func writeOutput<Output>(data: Output) where Output : DataProtocol

Write arbitrary DataProtocol bytes as part of an outbound message. This is intended to be used for adding headers around application data, or writing any other data that is generated or transformed by the protocol instance. It does not pass along data directly from the application. This function may be called as part of any framer callback, not just handleOutput. - Parameter data: Arbitrary DataProtocol to write on the connection.

method · iOS 13.0+

deliverInput

TypeScript
deliverInput(data: ArrayBuffer, message: NWProtocolFramer_Message, isComplete: boolean): void
Swift declaration
final func deliverInput(data: Data, message: NWProtocolFramer.Message, isComplete: Bool)

Deliver arbitrary data to the application. This is intended to deliver any data that is generated or transformed by the protocol instance. This function will incur a copy of bytes. - Parameter data: The bytes to deliver to the application. This must be non-nil. If an empty message needs to be delivered, use deliverInputNoCopy. - Parameter message: The message to associate with the received data. - Parameter isComplete: A boolean indicating whether or not this data represents the end of the message.

method · iOS 13.0+

scheduleWakeup

TypeScript
scheduleWakeup(wakeupTime: NWProtocolFramer_Instance_WakeupTime): void
Swift declaration
final func scheduleWakeup(wakeupTime: NWProtocolFramer.Instance.WakeupTime)

Schedule a wakeup on the framer instance for a number of milliseconds into the future. If this is called multiple times before the timeout is reached, the new value replaces the previous value. - Parameter wakeupTime: The number of milliseconds into the future at which to invoke the wakeup handler, or .forever, effectively unscheduling the timer.

get · iOS 13.0+

debugDescription

TypeScript
get debugDescription(): string
Swift declaration
final var debugDescription: String { get }

A textual representation of this instance, suitable for debugging. Calling this property directly is discouraged. Instead, convert an instance of any type to a string by using the `String(reflecting:)` initializer. This initializer works with any type, and uses the custom `debugDescription` property for types that conform to `CustomDebugStringConvertible`: struct Point: CustomDebugStringConvertible { let x: Int, y: Int var debugDescription: String { return "(\(x), \(y))" } } let p = Point(x: 21, y: 30) let s = String(reflecting: p) print(s) // Prints "(21, 30)" The conversion of `p` to a string in the assignment to `s` uses the `Point` type's `debugDescription` property.

method · iOS 13.0+

passThroughInput

TypeScript
passThroughInput(): void
Swift declaration
final func passThroughInput()

Mark the input side of the framer as a pass-through, which means the framer will not be notified of any further input data.

method · iOS 13.0+

passThroughOutput

TypeScript
passThroughOutput(): void
Swift declaration
final func passThroughOutput()

Mark the output side of the framer as a pass-through, which means the framer will not be notified of any further output data.

method · iOS 13.0+

writeOutputNoCopy

TypeScript
writeOutputNoCopy(length: number): void
Swift declaration
final func writeOutputNoCopy(length: Int) throws

Write bytes directly from the application without any transformation or copy. The bytes will start at the current output cursor used for parsing and will implicitly advance the cursor by the length being written. This function must only be called from within the handleOutput function on NWProtocolFramerImplementation. Throws an error if not called within the context of handleOutput, or if the specified length is longer than the current message. - Parameter length: Number of bytes from application to write.

method · iOS 13.0+

deliverInputNoCopy

TypeScript
deliverInputNoCopy(length: number, message: NWProtocolFramer_Message, isComplete: boolean): boolean
Swift declaration
final func deliverInputNoCopy(length: Int, message: NWProtocolFramer.Message, isComplete: Bool) -> Bool

Deliver bytes directly to the application without any transformation or copy. The bytes will start at the current input cursor used for parsing, and will implicitly advance the cursor by the length being delivered. - Parameter length: The number of input bytes to deliver. This will advance the parsing cursor by the specified number of bytes. To indicate the end of the message without delivering any data, a length of 0 may be passed along with isComplete. - Parameter message: The message to associate with the received data. - Parameter isComplete: A boolean indicating whether or not this data represents the end of the message. - Returns: `true` if the input was delivered immediately, or `false` if it will be delivered once more bytes become available.

method · iOS 13.0+

prependApplicationProtocol

TypeScript
prependApplicationProtocol(options: NWProtocolOptions): void
Swift declaration
final func prependApplicationProtocol(options: NWProtocolOptions) throws

Dynamically add a protocol to a connection establishment attempt "above" the framer protocol. This means that the protocol above will start running once the framer becomes ready by calling markReady(). This can only be used with framers that return a value of willMarkReady to their start handlers. An example of using this functionality is adding a security protocol, like TLS, above a framer once that framer completes its initial handshake. To ensure thread safety, this function can only be called in one of the callback blocks invoked on the framer, or in a block passed to NWProtocolFramer.Instance.async(). Throws an error if the protocol could not be added. This will fail if the framer is already marked ready. - Parameter options: Protocol options for an application protocol to dynamically add "above" the framer.

method · iOS 27.0+

prependApplicationProtocolIgnoringReady

TypeScript
prependApplicationProtocolIgnoringReady(options: NWProtocolOptions): void
Swift declaration
final func prependApplicationProtocolIgnoringReady(options: NWProtocolOptions) throws

Dynamically add a protocol to a connection establishment attempt "above" the framer protocol. This means that the protocol above will start running once the framer becomes ready by calling markReady(). This can only be used with framers that return a value of willMarkReady to their start handlers. An example of using this functionality is adding a security protocol, like TLS, above a framer once that framer completes its initial handshake. To ensure thread safety, this function can only be called in one of the callback blocks invoked on the framer, or in a block passed to NWProtocolFramer.Instance.async(). Throws an error if the protocol could not be added. This function differs from prependApplicationProtocol when the framer has already been marked ready. prependApplicationProtocol will throw an error if the framer was marked ready. prependApplicationProtocolIgnoringReady will still add the protocol and reset ready. The framer must markReady again. If there is data in-flight on the connection, the behavior is undefined. - Parameter options: Protocol options for an application protocol to dynamically add "above" the framer.

method · iOS 13.0+

async

TypeScript
async(execute: (() => void)): void
Swift declaration
final func async(execute: @escaping () -> Void)

Schedule a block asynchronously on the framer instance. This must be used anytime the caller wants to perform any other action on the framer instance while not directly in the callstack of a callback from the framer.

get · iOS 13.0+

local

TypeScript
get local(): (NWEndpoint) | null
Swift declaration
final var local: NWEndpoint? { get }

The local endpoint for the framer's connection

get · iOS 13.0+

remote

TypeScript
get remote(): (NWEndpoint) | null
Swift declaration
final var remote: NWEndpoint? { get }

The remote endpoint for the framer's connection

get · iOS 15.4+

options

TypeScript
get options(): NWProtocolFramer_Options
Swift declaration
final var options: NWProtocolFramer.Options { get }

The options for the framer's connection

method · iOS 13.0+

markReady

TypeScript
markReady(): void
Swift declaration
final func markReady()

Mark the connection associated with the framer instance as ready (see NWConnection.State.ready). This is intended to be used by protocols that require a handshake before being able to send application data. This should only be called if the return value to the start function was willMarkReady.

Skipped declarations

2 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

NWProtocolFramer.Instance.parseInput(minimumIncompleteLength:maximumLength:parse:)

callback cannot propagate synchronous failure

NWProtocolFramer.Instance.parseOutput(minimumIncompleteLength:maximumLength:parse:)

callback cannot propagate synchronous failure

All Network types →