<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Network",
  "identifier" : "/documentation/Network/NWProtocolWebSocket/Metadata",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Network"
    ],
    "preciseIdentifier" : "s:7Network19NWProtocolWebSocketC8MetadataC"
  },
  "title" : "NWProtocolWebSocket.Metadata"
}
-->

# NWProtocolWebSocket.Metadata

A WebSocket message you configure when sending and receiving packets.

```
class Metadata
```

## Topics

### Sending Messages

[`init(opcode: NWProtocolWebSocket.Opcode)`](/documentation/Network/NWProtocolWebSocket/Metadata/init(opcode:))

Initializes a WebSocket message with a specific type code.

[`enum Opcode`](/documentation/Network/NWProtocolWebSocket/Opcode)

Types of messages that you send and receive on a WebSocket connection.

[`func setPongHandler(DispatchQueue, handler: (NWError?) -> Void)`](/documentation/Network/NWProtocolWebSocket/Metadata/setPongHandler(_:handler:))

Sets a handler on a Ping message to be invoked when the corresponding Pong message is received.

[`var closeCode: NWProtocolWebSocket.CloseCode`](/documentation/Network/NWProtocolWebSocket/Metadata/closeCode)

The close code on a WebSocket message.

[`enum CloseCode`](/documentation/Network/NWProtocolWebSocket/CloseCode)

Types of codes used upon closing a WebSocket connection.

### Receiving Messages

[`let opcode: NWProtocolWebSocket.Opcode`](/documentation/Network/NWProtocolWebSocket/Metadata/opcode)

The type code of a WebSocket message.

[`var closeCode: NWProtocolWebSocket.CloseCode`](/documentation/Network/NWProtocolWebSocket/Metadata/closeCode)

The close code on a WebSocket message.

[`enum CloseCode`](/documentation/Network/NWProtocolWebSocket/CloseCode)

Types of codes used upon closing a WebSocket connection.

### Inspecting Handshake Results

[`var selectedSubprotocol: String?`](/documentation/Network/NWProtocolWebSocket/Metadata/selectedSubprotocol)

The subprotocol selected by the server during the WebSocket handshake.

[`var additionalServerHeaders: [(String, String)]?`](/documentation/Network/NWProtocolWebSocket/Metadata/additionalServerHeaders)

Additional HTTP headers sent by the server during the WebSocket handshake.

## Relationships

### Conforms To

[`Sendable`](/documentation/Swift/Sendable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

### Inherits From

[`NWProtocolMetadata`](/documentation/Network/NWProtocolMetadata)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)