WebSocket

WebSocket 1003 Unsupported Data vs 1012 Service Restart

Both WebSocket 1003 (Unsupported Data) and 1012 (Service Restart) belong to the WebSocket Close Codes category. 1003 indicates that an endpoint received a type of data it cannot accept. For example, a text-only endpoint received a binary message, or vice versa. Meanwhile, 1012 means that the server is terminating the connection because it is restarting. The client should reconnect after a brief delay.

คำอธิบาย

An endpoint received a type of data it cannot accept. For example, a text-only endpoint received a binary message, or vice versa.

เมื่อคุณพบเห็น

The client sent a binary frame to a server that only handles text, or a text frame to a binary-only endpoint. The receiver does not know how to process this data type.

วิธีแก้ไข

Verify the message type (text vs binary) matches what the server expects. Update your client to send the correct opcode for the data format.

คำอธิบาย

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

เมื่อคุณพบเห็น

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

วิธีแก้ไข

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.

ความแตกต่างหลัก

1.

WebSocket 1003: An endpoint received a type of data it cannot accept. For example, a text-only endpoint received a binary message, or vice versa.

2.

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

3.

You encounter 1003 when the client sent a binary frame to a server that only handles text, or a text frame to a binary-only endpoint. The receiver does not know how to process this data type.

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.

ควรใช้อันไหนเมื่อไร

For 1003 (Unsupported Data): Verify the message type (text vs binary) matches what the server expects. Update your client to send the correct opcode for the data format. 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.

เรียนรู้เพิ่มเติม