What is WebSocket?

Abisola | Feb 5, 2026

WebSocket is a protocol that upgrades an HTTP connection into a long-lived, two-way channel over TCP. After the upgrade, client and server can push messages at any time with small frames instead of repeating full HTTP requests. It is defined in RFC 6455 and is common for chat, live dashboards, collaboration tools, and some financial or gaming web clients.

How the upgrade and framing work

The client sends an HTTP request with Upgrade: websocket and Connection: Upgrade, plus a random key. The server answers 101 Switching Protocols with a computed Sec-WebSocket-Accept value. Once upgraded, both sides exchange WebSocket frames (text, binary, ping, pong, close). Ping and pong frames help keep connections alive through proxies and firewalls that drop idle TCP sessions.

WebSocket is not the same as a raw TCP socket in the browser: it is constrained by browser security policies and uses HTTP-compatible handshakes so it traverses most corporate proxies more easily than arbitrary TCP would.

WebSocket compared to polling and SSE

HTTP polling repeats full requests to check for updates. Long polling holds a request open until the server has data. Server-Sent Events give a one-way push from server to client over HTTP. WebSocket provides symmetric push in both directions on one connection, which reduces header overhead and suits interactive sessions.

Relevance to click fraud and ad tech

Ad tags, verification scripts, and publisher tools sometimes use WebSocket for real-time updates (inventory, bidding UI, internal ops consoles). Attackers and bots can also drive WebSocket traffic where sites expose APIs without the same bot defenses used on landing pages. Automated clients may show non-browser handshake or message patterns, which can feed suspicious behavior models together with IP and device signals.

WebSocket abuse is a subset of broader ad fraud and invalid traffic problems; defenses still map to monitoring, rate limits, authentication, and dedicated fraud detection. For paid search specifically, wasted spend ties back to click fraud and suspicious clicks even when the transport is not WebSocket.

Frequently Asked Questions

  • What is WebSocket used for on websites?

    WebSocket is a protocol that upgrades an HTTP connection into a long-lived, two-way TCP channel defined in RFC 6455. After a 101 Switching Protocols handshake, client and server push small text or binary frames anytime without repeating full HTTP requests. Common uses include chat, live dashboards, collaboration tools, and some financial web clients.

  • How is WebSocket different from HTTP polling?

    HTTP polling repeats full requests to check for updates, while long polling holds a request open until data arrives. Server-Sent Events push one-way from server to client over HTTP. WebSocket provides symmetric two-way push on one connection, reducing header overhead and suiting interactive sessions that need frequent bidirectional messages.

  • Does WebSocket matter for click fraud detection?

    Ad tags, verification scripts, and publisher tools sometimes use WebSocket for real-time inventory or bidding UI updates. Attackers and bots can also drive WebSocket traffic where sites expose APIs without the same defenses used on landing pages. Non-browser handshake or message patterns can feed suspicious behavior models together with IP and device signals.

  • What happens during a WebSocket handshake?

    The client sends an HTTP request with Upgrade websocket and Connection Upgrade headers plus a random key. The server responds with 101 Switching Protocols and a computed Sec-WebSocket-Accept value. Once upgraded, both sides exchange WebSocket frames including text, binary, ping, pong, and close messages over the persistent TCP connection.

Abisola

Abisola

Abisola handles content and support at ClickPatrol. She helps customers get more value from cleaner traffic data and writes practical resources about ad fraud, fake traffic, and smarter PPC decisions.