Skip to content
EN
Get Started

WebSocket

WebSocket is a protocol for two-way, real-time messages between a client and server over one long-lived connection, without a new HTTP request for every update.

Table of Contents (8 sections)

How WebSocket works

In the common HTTP/1.1 flow, the client starts with an HTTP request containing Upgrade: websocket. The server accepts by returning 101 Switching Protocols.

GET /stream HTTP/1.1
Host: example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Version: 13

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=

After that response, either side can send framed text or binary messages without waiting for a new request. Ping and pong frames can check whether the peer is still reachable.

The connection normally runs over TCP. A ws:// URL is unencrypted, while wss:// protects the connection with SSL/TLS, usually over port 443.

Common WebSocket uses

WebSocket suits applications that exchange frequent updates in both directions:

  • Live chat and notification feeds.
  • Financial dashboards and changing market data.
  • Multiplayer games that exchange player actions.
  • Collaborative editors that synchronize changes.

It isn’t necessary for ordinary pages or APIs that only need occasional request-and-response exchanges.

WebSocket vs HTTP

HTTP connections can be reused, but the client still starts each normal exchange. WebSocket changes that model after its opening handshake.

WebSocket HTTP request and response
Connection Usually long-lived May be reused across exchanges
Message direction Either side can send anytime Client normally starts
Best fit Frequent live updates Pages, files and standard APIs
Per-message overhead Small frames after setup Request and response headers

WebSockets through proxies

An HTTP proxy server can carry WebSocket traffic, but every intermediary on the path must support the connection:

  • Secure connections: An explicit proxy often uses CONNECT for wss://, then carries TLS and the WebSocket handshake through the tunnel.
  • Upgrade handling: A reverse proxy must forward the upgrade correctly or the server may never return 101.
  • Authentication: Invalid proxy credentials can produce a 407 response before the WebSocket reaches its server.
  • Idle timeouts: Proxies, firewalls and load balancers may close a connection that stays quiet too long.

A rotating proxy doesn’t change the exit IP for messages already traveling over an open WebSocket. Rotation usually occurs when you establish a new connection. A sticky session can keep reconnects on the same exit IP when the application expects a consistent client address.

FAQ

Is WebSocket built on HTTP?

Only during setup in the common HTTP/1.1 flow. After the 101 response, the connection carries WebSocket frames instead of normal HTTP requests and responses.

Can WebSockets work through an HTTP proxy?

Yes, if the proxy supports tunneling or WebSocket upgrades and allows long-lived connections. Proxy authentication, idle timeouts or missing upgrade headers can prevent the connection from opening.

Does a rotating proxy change IP during a WebSocket connection?

No, not while the same connection remains open. A new exit IP normally requires closing the WebSocket and establishing another connection.

Related Terms

View All Terms