WebSocket

WebSocket 1007 Invalid Payload Data vs 1009 Message Too Big

Both WebSocket 1007 (Invalid Payload Data) and 1009 (Message Too Big) belong to the WebSocket Close Codes category. 1007 indicates 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. Meanwhile, 1009 means that an endpoint is terminating the connection because it received a message that is too large for it to process.

説明

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.

このコードが表示される場合

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.

解決方法

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

説明

An endpoint is terminating the connection because it received a message that is too large for it to process.

このコードが表示される場合

The message payload exceeded the server's configured maximum frame or message size limit. Common when uploading large files or sending huge JSON payloads over WebSocket.

解決方法

Reduce the message size by chunking large payloads into smaller frames. Alternatively, increase the server's max message size configuration if the large payload is expected.

主な違い

1.

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.

2.

WebSocket 1009: An endpoint is terminating the connection because it received a message that is too large for it to process.

3.

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.

4.

You encounter 1009 when the message payload exceeded the server's configured maximum frame or message size limit. Common when uploading large files or sending huge JSON payloads over WebSocket.

どちらをいつ使うか

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. For 1009 (Message Too Big): Reduce the message size by chunking large payloads into smaller frames. Alternatively, increase the server's max message size configuration if the large payload is expected.

詳しく見る