WebSocket

WebSocket 1007 Invalid Payload Data vs 1012 Service Restart

Both WebSocket 1007 (Invalid Payload Data) and 1012 (Service Restart) 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, 1012 means that the server is terminating the connection because it is restarting. The client should reconnect after a brief delay.

Deskripsi

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.

Ketika Anda Melihatnya

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.

Cara Memperbaiki

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

Deskripsi

The server is terminating the connection because it is restarting. The client should reconnect after a brief delay.

Ketika Anda Melihatnya

The server is performing a planned restart — for example, during a deployment or configuration reload. The connection will be available again shortly.

Cara Memperbaiki

Implement automatic reconnection with a short delay (1-5 seconds). This code signals that reconnecting is expected and should succeed once the server is back up.

Perbedaan Utama

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 1012: The server is terminating the connection because it is restarting. The client should reconnect after a brief delay.

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 1012 when the server is performing a planned restart — for example, during a deployment or configuration reload. The connection will be available again shortly.

Kapan Menggunakan Yang Mana

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 1012 (Service Restart): Implement automatic reconnection with a short delay (1-5 seconds). This code signals that reconnecting is expected and should succeed once the server is back up.

Pelajari Lebih Lanjut