WebSocket

WebSocket 1000 Normal Closure vs 1011 Internal Error

Both WebSocket 1000 (Normal Closure) and 1011 (Internal Error) 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, 1011 means that the server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.

คำอธิบาย

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

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

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

วิธีแก้ไข

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.

คำอธิบาย

The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.

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

The server hit an unhandled exception or crashed while processing a WebSocket message. This is the WebSocket equivalent of HTTP 500 Internal Server Error.

วิธีแก้ไข

Check the server-side application logs for stack traces and exceptions. Fix the underlying bug that caused the crash and add proper error handling around message processing.

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

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 1011: The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.

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 1011 when the server hit an unhandled exception or crashed while processing a WebSocket message. This is the WebSocket equivalent of HTTP 500 Internal Server Error.

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

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 1011 (Internal Error): Check the server-side application logs for stack traces and exceptions. Fix the underlying bug that caused the crash and add proper error handling around message processing.

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