---
title: "close(code:reason:metadata:)"
framework: network
role: symbol
role_heading: Instance Method
path: "network/networkchannel/close(code:reason:metadata:)"
---

# close(code:reason:metadata:)

Send a WebSocket close frame on a connection.

## Declaration

```swift
func close(code: NWProtocolWebSocket.CloseCode = .protocolCode(.normalClosure), reason: String? = nil, @ProtocolMetadataBuilder metadata builder: () -> [NWProtocolMetadata] = {[]}) async throws
```

## Parameters

- `code`: Optional close code. Defaults to normal closure.
- `reason`: Optional reason string containing details about the closure.
- `builder`: A builder for specifying metadata about the content to send.

## Discussion

Discussion This may be called before the connection is ready, in which case the send will be enqueued until the connection is ready to send.
