TodayTools

Compare protocols

WebSocket vs HTTP: when you need a live two-way line

Donate
What brings you here?

The difference at a glance

WebSocket

WebSocket Protocol

Best for: Chat, live scores and games

Opens once, then both sides can talk at any time.
  1. Upgrade, from You
  2. 101 OK, from Chat server
  3. Hi, from You
  4. New message, from Chat server
  5. New message, from Chat server

HTTP

Hypertext Transfer Protocol

Best for: Pages, files and simple APIs

You ask, the server answers. The server never starts.
  1. Request, from You
  2. Response, from Server
  3. Request, from You
  4. Response, from Server

The short answer

HTTP is request and response: the browser asks, the server answers, and the server cannot speak first. WebSocket starts as an HTTP request, upgrades the same TCP connection, then keeps it open so both sides can send small messages at any time. Use WebSocket for chat, live scores and multiplayer. Use HTTP for pages, files and APIs.

Which one fits you?

Tick everything that is true for you.

What do you need?

Your pick shows here

Tick one or more lines and we weigh them for you.

WebSocket and HTTP side by side

WebSocket vs HTTP: differences row by row
What differsWebSocketHTTP
Who can speak firstBoth sides, any timeOnly the client
ConnectionOne long-lived TCP connectionReused with keep-alive, but each exchange is a new request
StartHTTP Upgrade, then 101 Switching ProtocolsDirectly with a request
Overhead per message2 to 14 bytes of frame headerOften hundreds of bytes of headers
CachingNoYes, by browsers and proxies
Addressesws:// (port 80) and wss:// (port 443)http:// (80) and https:// (443)
Scaling serversHarder: each user holds a connectionEasier: requests are independent
StandardRFC 6455RFC 9110 (semantics)

Watch each one work

Each page plays the real packets on a map, step by step, with every header explained.

Test yourself

Each line describes one of the two. Which one?

Question 1 of 8

Who can speak first

Both sides, any time

Questions people ask

Does WebSocket use HTTP?

Only to start. The browser sends an HTTP GET with an Upgrade: websocket header. After the server replies 101 Switching Protocols, the connection speaks WebSocket frames, not HTTP.

Is WebSocket faster than HTTP?

For many small messages, yes, because there is no new request and no big headers each time. For one large download, plain HTTP is just as fast.

What port does WebSocket use?

The same as the web: 80 for ws:// and 443 for wss://. That is why it passes most firewalls.

What about Server-Sent Events?

Server-Sent Events let the server push to the browser over normal HTTP, one way only. They are simpler when the client never needs to send messages back on the same line.

More comparisons

Donate