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.

Top comments (0)