WebSocket

WebSocket 1000 Normal Closure vs 1007 Invalid Payload Data

Both WebSocket 1000 (Normal Closure) and 1007 (Invalid Payload Data) belong to the WebSocket Close Codes category. 1000 indicates that the connection has been closed cleanly, meaning the purpose for which it was established has been fulfilled. Both endpoints agree the session is complete. Meanwhile, 1007 means that an endpoint received a message with payload data that is inconsistent with the message type. For example, a text message contained non-UTF-8 data.

Mô tả

The connection has been closed cleanly, meaning the purpose for which it was established has been fulfilled. Both endpoints agree the session is complete.

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

The WebSocket connection closed gracefully after both sides finished exchanging data. This is the expected close code for a successful session.

Cách khắc phục

No fix needed — this indicates everything worked as intended. If you did not expect the connection to close, check your application logic for premature close() calls.

Mô tả

An endpoint received a message with payload data that is inconsistent with the message type. For example, a text message contained non-UTF-8 data.

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

A text frame was received but its payload is not valid UTF-8. This commonly happens when binary data is accidentally sent as a text frame.

Cách khắc phục

Ensure text frames contain only valid UTF-8 encoded data. If you need to send raw bytes, use binary frames instead of text frames.

Sự khác biệt chính

1.

WebSocket 1000: The connection has been closed cleanly, meaning the purpose for which it was established has been fulfilled. Both endpoints agree the session is complete.

2.

WebSocket 1007: An endpoint received a message with payload data that is inconsistent with the message type. For example, a text message contained non-UTF-8 data.

3.

You encounter 1000 when the WebSocket connection closed gracefully after both sides finished exchanging data. This is the expected close code for a successful session.

4.

You encounter 1007 when a text frame was received but its payload is not valid UTF-8. This commonly happens when binary data is accidentally sent as a text frame.

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

For 1000 (Normal Closure): No fix needed — this indicates everything worked as intended. If you did not expect the connection to close, check your application logic for premature close() calls. For 1007 (Invalid Payload Data): Ensure text frames contain only valid UTF-8 encoded data. If you need to send raw bytes, use binary frames instead of text frames.

Tìm hiểu thêm