<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLSessionWebSocketTask/CloseCode-swift.enum",
  "metadataVersion" : "0.1.0",
  "role" : "Enumeration",
  "symbol" : {
    "kind" : "Enumeration",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:@E@NSURLSessionWebSocketCloseCode"
  },
  "title" : "URLSessionWebSocketTask.CloseCode"
}
-->

# URLSessionWebSocketTask.CloseCode

A code that indicates why a WebSocket connection closed.

```
enum CloseCode
```

## Overview

The WebSocket close codes follow the close codes defined in [RFC 6455](https://tools.ietf.org/html/rfc6455#section-7.4.1).

## Topics

### Close codes

[`URLSessionWebSocketTask.CloseCode.abnormalClosure`](/documentation/Foundation/URLSessionWebSocketTask/CloseCode-swift.enum/abnormalClosure)

A reserved code that indicates the connection closed without a close control frame.

[`URLSessionWebSocketTask.CloseCode.goingAway`](/documentation/Foundation/URLSessionWebSocketTask/CloseCode-swift.enum/goingAway)

A code that indicates an endpoint is going away.

[`URLSessionWebSocketTask.CloseCode.internalServerError`](/documentation/Foundation/URLSessionWebSocketTask/CloseCode-swift.enum/internalServerError)

A code that indicates the server terminated the connection because it encountered an unexpected condition.

[`URLSessionWebSocketTask.CloseCode.invalid`](/documentation/Foundation/URLSessionWebSocketTask/CloseCode-swift.enum/invalid)

A code that indicates the connection is still open.

[`URLSessionWebSocketTask.CloseCode.invalidFramePayloadData`](/documentation/Foundation/URLSessionWebSocketTask/CloseCode-swift.enum/invalidFramePayloadData)

A code that indicates the server terminated the connection because it received data inconsistent with the message’s type.

[`URLSessionWebSocketTask.CloseCode.mandatoryExtensionMissing`](/documentation/Foundation/URLSessionWebSocketTask/CloseCode-swift.enum/mandatoryExtensionMissing)

A code that indicates the client terminated the connection because the server didn’t negotiate a required extension.

[`URLSessionWebSocketTask.CloseCode.messageTooBig`](/documentation/Foundation/URLSessionWebSocketTask/CloseCode-swift.enum/messageTooBig)

A code that indicates an endpoint is terminating the connection because it received a message too big for it to process.

[`URLSessionWebSocketTask.CloseCode.noStatusReceived`](/documentation/Foundation/URLSessionWebSocketTask/CloseCode-swift.enum/noStatusReceived)

A reserved code that indicates an endpoint expected a status code and didn’t receive one.

[`URLSessionWebSocketTask.CloseCode.normalClosure`](/documentation/Foundation/URLSessionWebSocketTask/CloseCode-swift.enum/normalClosure)

A code that indicates normal connection closure.

[`URLSessionWebSocketTask.CloseCode.policyViolation`](/documentation/Foundation/URLSessionWebSocketTask/CloseCode-swift.enum/policyViolation)

A code that indicates an endpoint terminated the connection because it received a message that violates its policy.

[`URLSessionWebSocketTask.CloseCode.protocolError`](/documentation/Foundation/URLSessionWebSocketTask/CloseCode-swift.enum/protocolError)

A code that indicates an endpoint terminated the connection due to a protocol error.

[`URLSessionWebSocketTask.CloseCode.tlsHandshakeFailure`](/documentation/Foundation/URLSessionWebSocketTask/CloseCode-swift.enum/tlsHandshakeFailure)

A reserved code that indicates the connection closed due to the failure to perform a TLS handshake.

[`URLSessionWebSocketTask.CloseCode.unsupportedData`](/documentation/Foundation/URLSessionWebSocketTask/CloseCode-swift.enum/unsupportedData)

A code that indicates an endpoint terminated the connection after receiving a type of data it can’t accept.



---

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)