One Logo Pool Ball
Network · IOS API REFERENCE

NWConnectionGroup

class · iOS 14.0+ · SDK 27.1

final class NWConnectionGroup

An `NWConnectionGroup` is an object that represents an active session with multiple entities or resources on the network. This can be used to send and receive messages within the group, for example sending and receiving multicast traffic. You can create an `NWConnection` from a message to communicate with a single endpoint in the group.

Members (17)

get · iOS 14.0+

descriptor

TypeScript
get descriptor(): SDKHandle
Swift declaration
final let descriptor: any NWGroupDescriptor

The group descriptor used by the connection group.

get · iOS 14.0+

parameters

TypeScript
get parameters(): NWParameters
Swift declaration
final let parameters: NWParameters

The set of parameters with which the connection group was created.

get · iOS 14.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 14.0+

setReceiveHandler

TypeScript
setReceiveHandler(maximumMessageSize?: number, rejectOversizedMessages?: boolean, handler?: (((arg0: NWConnectionGroup_Message, arg1: (ArrayBuffer) | null, arg2: boolean) => void)) | null): void
Swift declaration
@preconcurrency final func setReceiveHandler(maximumMessageSize: Int = Int.max, rejectOversizedMessages: Bool = true, handler: (@Sendable (NWConnectionGroup.Message, Data?, Bool) -> Void)?)

Provide a handler for any received messages sent from members of the group to the local endpoint. `maximumMessageSize` defines the size of the largest message that will be delivered to the handler closure. Defaults to `Int.max`. `rejectOversizedMessages` indicates whether or not messages larger than `maximumMessageSize` should be rejected. If `rejectOversizedMessages` is `false`, large messages will be sent to handler closure as partial messages. Defaults to `true`.

get · iOS 14.0+

stateUpdateHandler

TypeScript
get stateUpdateHandler(): (((arg0: NWConnectionGroup_State) => Promise<void>)) | null
Swift declaration
@preconcurrency final var stateUpdateHandler: (@Sendable (NWConnectionGroup.State) -> Void)? { get set }

Set a block to be called when the group's state changes, which may be called multiple times until the group is cancelled.

set · iOS 14.0+

stateUpdateHandler

TypeScript
set stateUpdateHandler(value: (((arg0: NWConnectionGroup_State) => void)) | null)
Swift declaration
@preconcurrency final var stateUpdateHandler: (@Sendable (NWConnectionGroup.State) -> Void)? { get set }

Set a block to be called when the group's state changes, which may be called multiple times until the group is cancelled.

get · iOS 15.0+

newConnectionHandler

TypeScript
get newConnectionHandler(): (((arg0: NWConnection) => Promise<void>)) | null
Swift declaration
@preconcurrency final var newConnectionHandler: (@Sendable (NWConnection) -> Void)? { get set }

Handler to be called for new connections initiated by the peer of this group.

set · iOS 15.0+

newConnectionHandler

TypeScript
set newConnectionHandler(value: (((arg0: NWConnection) => void)) | null)
Swift declaration
@preconcurrency final var newConnectionHandler: (@Sendable (NWConnection) -> Void)? { get set }

Handler to be called for new connections initiated by the peer of this group.

method · iOS 14.0+

send

TypeScript
send(content: (ArrayBuffer) | null, to: (NWEndpoint) | null, message: NWConnectionGroup_Message, completion: ((arg0: (NWError) | null) => void)): void
Swift declaration
@preconcurrency final func send(content: Data?, to: NWEndpoint? = nil, message: NWConnectionGroup.Message = .default, completion: @escaping (NWError?) -> Void)

Send data to a particular endpoint within the group. The endpoint can represent multiple peers, such as an IP multicast address, or a specific peer in the group. If the endpoint is `nil`, the message will be sent to all members in the group. The endpoint defaults to `nil`. The message defaults to `.default`. The completion will be invoked with an optional error when the send operation has completed.

init · iOS 14.0+

init

TypeScript
static init(with_: SDKHandle, using: NWParameters): NWConnectionGroup
Swift declaration
init(with: any NWGroupDescriptor, using: NWParameters)

Create a group with a descriptor, which identifies the group addresses for communication, and a set of parameters, which defines the protocols to use for communication with the group. Group creation can fail if the group descriptor is invalid.

get · iOS 14.0+

queue

TypeScript
get queue(): (_Dispatch_DispatchQueue) | null
Swift declaration
final var queue: DispatchQueue? { get }

Get queue used for delivering block handlers, such as `stateUpdateHandler`, `messageHandler`, and the completion to calls to `send`. If the group has not yet been started, the queue will be `nil`. Once the group has been started, the queue will be non-nil.

method · iOS 14.0+

start

TypeScript
start(queue: _Dispatch_DispatchQueue): void
Swift declaration
final func start(queue: DispatchQueue)

Start the group and provide a queue on which callback handlers will be executed. Start should only be called once on a group, and multiple calls to start will be ignored.

get · iOS 14.0+

state

TypeScript
get state(): NWConnectionGroup_State
Swift declaration
final var state: NWConnectionGroup.State { get }
method · iOS 14.0+

cancel

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

Cancel is asynchronous and the group state will eventually transition to `.cancelled`. Subsequent calls to `cancel` are ignored.

method · iOS 15.0+

extract

TypeScript
extract(connectionTo?: (NWEndpoint) | null, using?: (NWProtocolOptions) | null): (NWConnection) | null
Swift declaration
final func extract(connectionTo: NWEndpoint? = nil, using: NWProtocolOptions? = nil) -> NWConnection?

Extract a connection from the connection group. For a multiplex connection group, this means that a new stream is opened and the NWConnection object is returned. For non-multiplex connection groups, a connection to the specified endpoint will be returned if allowed by the group descriptor. The connection can be re-inserted into the group later. Once reinserted, the connection group will handle subsequent messages from this remote endpoint.

method · iOS 15.0+

metadata

TypeScript
metadata(definition: NWProtocolDefinition): (NWProtocolMetadata) | null
Swift declaration
final func metadata(definition: NWProtocolDefinition) -> NWProtocolMetadata?
method · iOS 15.0+

reinsert

TypeScript
reinsert(connection: NWConnection): boolean
Swift declaration
final func reinsert(connection: NWConnection) -> Bool

Reinsert a connection into a connection group. Once reinserted, the connection group will handle subsequent messages from this remote endpoint, and any outstanding reads on the connection will be cancelled.

Skipped declarations

No declarations were skipped in this snapshot.

All Network types →