Search code examples
httpwebsockettcp

WebSocket half-open?


I've got a simple question regarding WebSocket. I know that the WebSocket protocol is based on TCP. And I know that TCP connections are half-open.

Does this mean that WebSocket-connections are half-open as well? I tried to search for this in the internet but could not find a reliable source.


Solution

  • Half-open refers to state where the socket connection is out of sync.

    This is an error that might be caused, for example, when a mobile device moves out of the reception area and only one side (i.e., the device) attempts to send data (and fails).

    In this example, the mobile device will mark the connection as closed, while the server will be waiting for data, blissfully unaware that the connection was disrupted.

    You can read more about this here.

    TCP/IP connections are not half-open unless an error occurs. They can become half open (as can the WebSocket connections that rely on the TCP/IP layer).

    To solve this issue, a periodic ping is used. This ping will eventually expose a half-open connection, so the error can be detected and the connection can be closed.