-1

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.

O. Jones
  • 103,626
  • 17
  • 118
  • 172
Sushiman
  • 55
  • 6
  • 1
    I think you might be confusing terminology... are you sure you meant "[half-open](https://en.wikipedia.org/wiki/TCP_half-open)" connections (when one side believes the connection is open and the other believes the connection is closed)? – Myst Oct 30 '18 at 04:40
  • Yes, that is what I was referring to. Is there a problem on my understanding of the matter? – Sushiman Oct 30 '18 at 08:27

2 Answers2

2

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.

Myst
  • 18,516
  • 2
  • 45
  • 67
0

I suspect this is what OP was referring to, and it is at least somewhat commonly used. For example, it is the reason HTTP POST requests will sometimes work without a Content-Length or Transfer-Encoding header (though this is a violation of the spec)

In answer to that question: no, websockets can't do that

See RFC 6455 - 5.5.1:

If an endpoint receives a Close frame and did not previously send a Close frame, the endpoint MUST send a Close frame in response. ... It SHOULD do so as soon as practical. An endpoint MAY delay sending a Close frame until its current message is sent (for instance, if the majority of a fragmented message is already sent, an endpoint MAY send the remaining fragments before sending a Close frame). However, there is no guarantee that the endpoint that has already sent a Close frame will continue to process data.

9072997
  • 849
  • 7
  • 21