According to here:
The HTTP Upgrade header requests that the server switch the application-layer protocol from HTTP to the WebSocket protocol.
The client handshake established a HTTP-on-TCP connection between IE10 and server. After the server returns its 101 response, the application-layer protocol switches from HTTP to WebSockets which uses the previously established TCP connection.
HTTP is completely out of the picture at this point. Using the lightweight WebSocket wire protocol, messages can now be sent or received by either endpoint at any time.
So, my understanding is, after the 1st client finished handshake with the server, the server's 80 port will be monopolized by the WebSocket protocol. And the HTTP is no longer working on 80 port.
So how could the 2nd client exchange handshake with the server. After all the WebSocket handshake is in HTTP format.
ADD 1
Thanks for all the answers so far. They are really helpful.
Now I understand that the same server's 80 port is shared by multiple TCP
connections. And this sharing is totally OK because TCP
connections are identified by a 5-element tuple as Jan-Philip Gehrcke
pointed out.
I'd like to add a few thoughts.
Both WebSocket
and HTTP
are merely application level protocols. Usually they both rely on the TCP
protocol as their transport.
Why choose port 80?
WebSocket design intentionally choose server's port 80 for both handshake and following communication. I think the designer wants to make WebSocket communication look like normal HTTP communication from the transport level's perspective (i.e. the server port number is still 80). But according to jfriend00
's answer, this trick doesn't always fool the network infrastructures.
How does the protocol shift from HTTP to WebSocket happen?
From RFC 6455 - WebSocket protocol
Basically it is intended to be as close to just exposing raw TCP to script as possible given the constraints of the Web. Itβs also designed in such a way that its servers can share a port with HTTP servers, by having its handshake be a valid HTTP Upgrade request. One could conceptually use other protocols to establish client-server messaging, but the intent of WebSockets is to provide a relatively simple protocol that can coexist with HTTP and deployed HTTP infrastructure (such as proxies) and that is as close to TCP as is safe for use with such infrastructure given security considerations, with targeted additions to simplify usage and keep simple things simple (such as the addition of message semantics).
So I think I am wrong on the following statement:
The handshake request mimic HTTP request but the communication that follows don't. The handshake request arrives at the server on port 80. Because it's 80 port, server will treat it with HTTP protocol. And that's why the WebSocket handshake request must be in HTTP format. If so, I think the HTTP protocol MUST be modified/extended to recognize those WebSocket-specific things. Otherwise it won't realize it should yield to WebSocket protocol.
I think it should be understood like this:
WebSocket communication starts with a valid HTTP request from client to server. So it is the server that follows the HTTP protocol to parse the handshake request and identify the begging for protocol change. And it is the server that switches the protocol. So HTTP protocol doesn't need to change. HTTP protocol doesn't even need to know about WebSocket.
WebSocket and Comet
So WebSocket is different from Comet technologies in that WebSoket doesn't limit itself within the current HTTP realm to solve the bi-directional communication issue.
ADD 2
A related question: How does a browser establish connection with a web server on 80 port? Details?