WebSocket

WebSocket 1005 No Status Received vs 1008 Policy Violation

Both WebSocket 1005 (No Status Received) and 1008 (Policy Violation) belong to the WebSocket Close Codes category. 1005 indicates that a reserved value that indicates no status code was present in the Close frame. This code must not be set by an endpoint when sending a Close frame. Meanwhile, 1008 means that an endpoint is terminating the connection because it received a message that violates its policy. This is a generic code when none of the other codes (1003, 1009) are suitable.

Mô tả

A reserved value that indicates no status code was present in the Close frame. This code must not be set by an endpoint when sending a Close frame.

Khi bạn thấy mã này

The peer closed the connection with a Close frame that contained no status code payload. Your WebSocket library surfaces 1005 as a sentinel to indicate the absence of a code.

Cách khắc phục

This is an internal indicator, not a wire protocol value. If you see it frequently, the remote peer may have a bug where it sends empty Close frames — check the peer's implementation.

Mô tả

An endpoint is terminating the connection because it received a message that violates its policy. This is a generic code when none of the other codes (1003, 1009) are suitable.

Khi bạn thấy mã này

The server rejected a message because it violated an application-level policy — for example, sending messages too rapidly, exceeding rate limits, or failing authentication after the handshake.

Cách khắc phục

Review the server's documented policies and constraints. Check for rate limiting, authentication token expiry, or forbidden message content that triggered the rejection.

Sự khác biệt chính

1.

WebSocket 1005: A reserved value that indicates no status code was present in the Close frame. This code must not be set by an endpoint when sending a Close frame.

2.

WebSocket 1008: An endpoint is terminating the connection because it received a message that violates its policy. This is a generic code when none of the other codes (1003, 1009) are suitable.

3.

You encounter 1005 when the peer closed the connection with a Close frame that contained no status code payload. Your WebSocket library surfaces 1005 as a sentinel to indicate the absence of a code.

4.

You encounter 1008 when the server rejected a message because it violated an application-level policy — for example, sending messages too rapidly, exceeding rate limits, or failing authentication after the handshake.

Khi nào dùng cái nào

For 1005 (No Status Received): This is an internal indicator, not a wire protocol value. If you see it frequently, the remote peer may have a bug where it sends empty Close frames — check the peer's implementation. For 1008 (Policy Violation): Review the server's documented policies and constraints. Check for rate limiting, authentication token expiry, or forbidden message content that triggered the rejection.

Tìm hiểu thêm