DEV Community

clusterO
clusterO

Posted on

About WebSocket

WebSocket is a computer communications protocol, providing full-duplex communication channels over a single TCP connection. The WebSocket protocol was standardized by the IETF as RFC 6455 in 2011, and the WebSocket API specification was standardized by the W3C as an extension to the HTML5 specification.

WebSocket is designed to be implemented in web browsers and web servers, but it can be used by any client or server application. For example, a desktop browser can use a WebSocket server as a proxy to send requests to another server.

The WebSocket protocol is based on the HTTP protocol. The WebSocket protocol enables two-way communication between a client (e.g., a web browser) and a server (e.g., a web server). It provides full-duplex communication channels over a single TCP connection. The WebSocket protocol does not rely on opening multiple HTTP connections (e.g., TCP connections) for message passing.

The WebSocket protocol uses the HTTP/1.1 Upgrade mechanism, but it is not restricted to HTTP/1.1 requests and responses. A WebSocket connection is established by opening a TCP connection to port 80 (or port 443) at the originating endpoint, which is then used for two-way communication with the remote endpoint. A WebSocket connection through an HTTP proxy can be established by using an HTTP CONNECT method request.

The WebSocket protocol is layered on top of TCP, so it inherits all of TCP's features, such as its flow control mechanisms and security features (such as TLS). In addition, the WebSocket protocol provides many new features that are not present in HTTP/1.1, such as binary message framing and compression of data using message frames.

WebSocket protocols are implemented in various software libraries that are available for different programming languages and platforms, including JavaScript libraries like SockJS and Node.js libraries like Socket.IO and Faye, Ruby libraries like Faye and EventMachine, Python libraries like Twisted and Tornado, Java libraries like Jetty and Ratpack, PHP libraries like PHP-WebSocket and Pusher, C# libraries like Newtonsoft's WebSocket implementation for .NET Framework 4 or SocketRocket, Objective-C libraries like SocketRocket or SocketStream, Scala libraries like Scalatra or Akka HTTP and many others.

The WebSocket protocol has also been implemented in C using libwebsockets or in Erlang using websocket-erlang; both are available on GitHub.

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Instrument, monitor, fix: a hands-on debugging session

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️