What is a WebSocket?

WebSocket is a protocol that enables real time two way communication between a browser and a server. CloudSonic supports WebSocket connections out of the box on all application and API hosting plans.

CloudSonic
CloudSonic
Last Updated September 10, 2026

TL;DR WebSocket

A WebSocket is a communication protocol that provides a persistent, full-duplex connection between a client and a server over a single TCP connection. Unlike standard HTTP where the client sends a request and waits for the server to respond before the connection closes, a WebSocket connection stays open and allows both the client and server to send messages to each other at any time without a new request being needed. This makes WebSockets the right choice for any application that requires real time communication, such as live chat, collaborative editing, multiplayer games, live dashboards, and financial data feeds. WebSockets are initiated via an HTTP upgrade request and then operate over their own protocol. CloudSonic supports WebSocket connections out of the box on all application hosting and API hosting plans. The Nginx configuration handles WebSocket proxying correctly by default so no additional setup is needed on your end.

How WebSockets Work

A WebSocket connection begins as a standard HTTP request. The client sends an HTTP request with a special Upgrade header indicating it wants to switch protocols. If the server supports WebSockets it responds with an HTTP 101 Switching Protocols status and the connection is upgraded from HTTP to the WebSocket protocol. From this point the connection remains open and both the client and server can send messages to each other at any time without a new request being required. Messages can be text or binary data and are framed with a small header that indicates the message type and length. Either party can close the connection by sending a close frame. This persistent bidirectional connection is what makes WebSockets suitable for real time applications. A chat application can push new messages to all connected clients the instant they arrive. A live dashboard can push updated metrics every second. A collaborative editor can synchronise changes between users as they type. None of these would be practical with standard HTTP request-response cycles.

Why WebSockets Matter for Your Website

For most traditional websites and blogs, WebSockets are not relevant and standard HTTP request-response cycles are perfectly adequate. WebSockets become essential when your application needs to push data to users in real time without those users having to request it. A live chat widget that shows messages as they are sent, a collaboration tool that synchronises edits between users, a sports score tracker that updates without page refreshes, or a trading dashboard that shows live price movements all require a persistent connection that can deliver data the moment it is available. The alternative to WebSockets for these use cases is polling, where the browser sends a new HTTP request every few seconds asking if anything has changed. Polling is inefficient, slow, and creates unnecessary server load. WebSockets replace polling with a single persistent connection that the server can use to push updates instantly, delivering a genuinely real time experience at a fraction of the server cost.

Frequently Asked Questions on WebSocket

Do WebSockets work through Cloudflare?

Yes. Cloudflare Enterprise supports WebSocket proxying, meaning WebSocket connections from visitors pass through Cloudflare's network to your origin server without any special configuration. The initial HTTP upgrade request is handled correctly and the persistent connection is maintained through the Cloudflare proxy layer.

What is the difference between WebSockets and Server-Sent Events?

WebSockets provide a full-duplex connection where both client and server can send messages to each other at any time. Server-Sent Events provide a one-way connection where the server can push updates to the client but the client cannot send messages back over the same connection. SSE is simpler to implement and sufficient for use cases like live notifications or feed updates where the client only needs to receive data. WebSockets are needed when the client also needs to send data in real time, such as in chat applications or collaborative tools.

Can WebSockets cause performance issues on a shared server?

WebSocket connections are persistent and each one consumes a small amount of server memory and a file descriptor for as long as it is open. A server with thousands of simultaneous WebSocket connections needs to be sized accordingly. CloudSonic's server configuration raises the open file descriptor limit to 65535 to accommodate high connection counts, and the event-driven architecture of Nginx handles large numbers of persistent connections efficiently.