<!--
{
  "documentType" : "article",
  "framework" : "Network",
  "identifier" : "/documentation/Network/websocket-options",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "WebSocket Options"
}
-->

# WebSocket Options

Configure options for connections that use WebSocket.

## Topics

### Creating WebSocket Connections

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

Accesses the system definition of the WebSocket protocol.

[`nw_ws_create_options(_:)`](/documentation/Network/nw_ws_create_options(_:))

Initializes a default set of WebSocket connection options.

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

Supported versions of the WebSocket protocol.

[`nw_ws_options_set_auto_reply_ping(_:_:)`](/documentation/Network/nw_ws_options_set_auto_reply_ping(_:_:))

Configures the connection to automatically reply to Ping messages instead of delivering them to you.

[`nw_ws_options_set_maximum_message_size(_:_:)`](/documentation/Network/nw_ws_options_set_maximum_message_size(_:_:))

Sets the maximum allowed message size, in bytes, to be received by the WebSocket connection.

### Configuring Client Handshakes

[`nw_ws_options_add_additional_header(_:_:_:)`](/documentation/Network/nw_ws_options_add_additional_header(_:_:_:))

Adds additional HTTP header fields to be sent by the client during the WebSocket handshake.

[`nw_ws_options_add_subprotocol(_:_:)`](/documentation/Network/nw_ws_options_add_subprotocol(_:_:))

Adds to the list of supported application protocols that will be presented to a WebSocket server during connection establishment.

[`nw_ws_options_set_skip_handshake(_:_:)`](/documentation/Network/nw_ws_options_set_skip_handshake(_:_:))

Specifies whether the WebSocket protocol skips its handshake and begins framing data once the underlying connection is established.

### Handling WebSocket Messages

[`nw_protocol_metadata_is_ws(_:)`](/documentation/Network/nw_protocol_metadata_is_ws(_:))

Checks whether a metadata object represents a WebSocket message.

[`nw_ws_create_metadata(_:)`](/documentation/Network/nw_ws_create_metadata(_:))

Initializes a WebSocket message with a specific type code.

[`nw_ws_metadata_get_opcode(_:)`](/documentation/Network/nw_ws_metadata_get_opcode(_:))

Checks the type code on a WebSocket message.

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

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

[`nw_ws_metadata_set_close_code(_:_:)`](/documentation/Network/nw_ws_metadata_set_close_code(_:_:))

Sets a close code on a WebSocket message.

[`nw_ws_metadata_get_close_code(_:)`](/documentation/Network/nw_ws_metadata_get_close_code(_:))

Accesses the close code on a WebSocket message.

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

Types of codes used upon closing a WebSocket connection.

[`nw_ws_metadata_set_pong_handler(_:_:_:)`](/documentation/Network/nw_ws_metadata_set_pong_handler(_:_:_:))

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

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

A handler that indicates that a Pong message has been received for a previously sent Ping message, or that an error was encountered.

[`nw_ws_metadata_copy_server_response(_:)`](/documentation/Network/nw_ws_metadata_copy_server_response(_:))

Accesses the WebSocket server’s response sent during the handshake.

### Handling Server Handshakes

[`nw_ws_options_set_client_request_handler(_:_:_:)`](/documentation/Network/nw_ws_options_set_client_request_handler(_:_:_:))

Sets a handler to react to as a server to inbound WebSocket client handshakes.

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

A handler that delivers inbound client handshake requests.

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

A WebSocket handshake request sent from a client to a server.

[`nw_ws_request_enumerate_subprotocols(_:_:)`](/documentation/Network/nw_ws_request_enumerate_subprotocols(_:_:))

Enumerates the supported subprotocols in a WebSocket message.

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

A block that enumerates the supported subprotocols in a WebSocket client request.

[`nw_ws_request_enumerate_additional_headers(_:_:)`](/documentation/Network/nw_ws_request_enumerate_additional_headers(_:_:))

Enumerates additional HTTP headers in a WebSocket message.

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

A block that enumerates additional HTTP headers in a WebSocket client request.

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

A WebSocket handshake reponse sent from a server to a client.

[`nw_ws_response_create(_:_:)`](/documentation/Network/nw_ws_response_create(_:_:))

Initializes a WebSocket server response with a status and selected subprotocol.

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

Status values that are sent with a WebSocket server response.

[`nw_ws_response_add_additional_header(_:_:_:)`](/documentation/Network/nw_ws_response_add_additional_header(_:_:_:))

Adds an additional HTTP header to a WebSocket server response.

[`nw_ws_response_get_status(_:)`](/documentation/Network/nw_ws_response_get_status(_:))

Accesses the status of a WebSocket server response.

[`nw_ws_response_get_selected_subprotocol(_:)`](/documentation/Network/nw_ws_response_get_selected_subprotocol(_:))

Accesses the selected subprotocol in a WebSocket server response.

[`nw_ws_response_enumerate_additional_headers(_:_:)`](/documentation/Network/nw_ws_response_enumerate_additional_headers(_:_:))

Enumerates the additional HTTP headers in a WebSocket server response.



---

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)