Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Socket Protocol Handshake vs. Switching Protocols

Tags:

What's the difference between these two response statuses:

HTTP/1.1 101 Web Socket Protocol Handshake  HTTP/1.1 101 Switching Protocols 

Does it matter which one I get?

like image 624
0101 Avatar asked Mar 14 '14 16:03

0101


People also ask

What is WebSocket handshake?

WebSockets - Overview In computer science, handshaking is a process that ensures the server is in sync with its clients. Handshaking is the basic concept of Web Socket protocol. The following diagram shows the server handshake with various clients −

What is the difference between WS and WSS?

The wss protocol establishes a WebSocket over an encrypted TLS connection, while the ws protocol uses an unencrypted connection. At this point, the network connection remains open and can be used to send WebSocket messages in either direction.

What are switching protocols?

101 Switching Protocols is a status code that's used for a server to indicate that the TCP conncection is about to be used for a different protocol. The best example of this is in the WebSocket protocol. WebSocket uses a HTTP handshake when creating the connection, mainly for security reasons.

What protocol does WebSocket use?

The WebSocket protocol is an independent TCP-based protocol. Its only relationship to HTTP is that its handshake is interpreted by HTTP servers as an Upgrade request. By default the WebSocket protocol uses port 80 for regular WebSocket connections and port 443 for WebSocket connections tunneled over TLS [RFC2818].


1 Answers

There is no difference whatsoever. What is important is the 101 response code to indicate the handshake is progressing. This is defined in RFC 6455:

The leading line from the client follows the Request-Line format. The leading line from the server follows the Status-Line format. The Request-Line and Status-Line productions are defined in [RFC2616].

...

The handshake from the server is much simpler than the client handshake. The first line is an HTTP Status-Line, with the status code 101:

HTTP/1.1 101 Switching Protocols

Any status code other than 101 indicates that the WebSocket handshake has not completed and that the semantics of HTTP still apply.

The text of the Status-Line is arbitrary, the server can use whatever text it wants, per RFC 2616:

Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF

...

The Status-Code element is a 3-digit integer result code of the attempt to understand and satisfy the request. These codes are fully defined in section 10. The Reason-Phrase is intended to give a short textual description of the Status-Code. The Status-Code is intended for use by automata and the Reason-Phrase is intended for the human user. The client is not required to examine or display the Reason-Phrase.

Switching Protocols just happens to be what the examples in RFC 6455 use, but that is not a requirement.

like image 124
Remy Lebeau Avatar answered Oct 01 '22 00:10

Remy Lebeau