Junior — Middle
What protocols are used when establishing a WebSocket connection?
sobes.tech AI
Answer from AI
When establishing a WebSocket connection, the HTTP/1.1 protocol is used for the initial handshake. The client sends an HTTP request with the header Upgrade: websocket to initiate the transition from HTTP to the WebSocket protocol.
Main protocols and steps:
- HTTP/1.1 — used for the initial connection request.
- WebSocket Protocol (RFC 6455) — after a successful handshake, the connection switches to a bidirectional WebSocket protocol over TCP.
Thus, first, an HTTP request with upgrade headers occurs, then a persistent TCP connection with WebSocket protocol is established for real-time message exchange.