Class

NWListener

An object you use to listen for incoming network connections.

Declaration

final class NWListener

Topics

Creating Listeners

init(using: NWParameters, on: NWEndpoint.Port)

Initializes a network listener, with an optional local port.

func start(queue: DispatchQueue)

Registers for listening, and sets the queue on which all listener events are delivered.

var stateUpdateHandler: ((NWListener.State) -> Void)?

A handler that receives listener state updates.

enum NWListener.State

States indicating whether a listener is able to accept incoming connections.

var port: NWEndpoint.Port?

The port on which the listener can accept connections.

func cancel()

Stops listening for inbound connections.

Receiving Connections

var newConnectionHandler: ((NWConnection) -> Void)?

A handler that receives inbound connections.

var newConnectionLimit: Int

The remaining number of inbound connections to deliver before rejecting connections.

Beta
static let InfiniteConnectionLimit: Int

A static value to indicate that inbound connections should not be limited.

Beta

Advertising Bonjour Services

var service: NWListener.Service?

A Bonjour service that advertises the listener on the local network.

struct NWListener.Service

A description used to advertise the Bonjour service that a listener provides.

var serviceRegistrationUpdateHandler: ((NWListener.ServiceRegistrationChange) -> Void)?

A handler that receives updates for the service endpoint being advertised.

enum NWListener.ServiceRegistrationChange

Changes to how a network listener's service is advertised.

Inspecting Listeners

let parameters: NWParameters

The parameters used to initialize the listener.

var queue: DispatchQueue?

The queue on which listener events are delivered.

var debugDescription: String

The description of the listener.

Relationships

See Also

Connections and Listeners

class NWConnection

A bidirectional data connection between a local endpoint and a remote endpoint.

class NWBrowser

An object you use to browse for available network services.

Beta
class NWEthernetChannel

An object you use to send and receive custom Ethernet frames.

Beta

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software