What is the WebSocket Protocol?

Map Of Internet 1973

About

WebSocket is a protocol that provides full-duplex communication channels over a single TCP connection between:

with lower overheads, facilitating real-time data transfer from and to the server.

Implementation

WebSocket is running over a single TCP connection where:

  • The server can send content to the client without being first requested by the client.
  • The communications are done over TCP port number 80 (or 443 in the case of TLS-encrypted connections)

Websocket is located at layer 7 in the OSI model (and, as such, depend on TCP at layer 4)

RFC 6455 states that WebSocket is designed to:

Similar two-way browser-server communications have been achieved in non-standardized ways using stopgap technologies such as Comet.

Standardization

The WebSocket:

  • protocol was standardized by the IETF as RFC 6455 in 2011,
  • API in Web IDL is being standardized by the W3C.

Usage

Push real-time updates such as:

  • notifications,
  • vote counts,
  • new answers
  • comments

Library

Native Javascript

WebAPI WebSocket

var ws = new WebSocket('ws://host.com/path');

ws.onopen = () => {
  // connection opened
  ws.send('something'); // send a message
};

ws.onmessage = (e) => {
  // a message was received
  console.log(e.data);
};

ws.onerror = (e) => {
  // an error occurred
  console.log(e.message);
};

ws.onclose = (e) => {
  // connection closed
  console.log(e.code, e.reason);
};

Websocket.io

Example

Documentation / Reference





Discover More
Browsersync.io

Browser Sync serves the content, detects changes, refreshes the browser, and offers many customization's. How to use it to develop with live reloading. The reload will work: for the builtin web server...
Browser
Chrome DevTool protocol (CDP)

The is a API that permits to call browsers implementing the CDP api (chrome of course but also any other browser implementation ) via json RPC. The protocol is used to communicate with Chrome and drive...
Card Puncher Data Processing
Software Design - Real time

Real time refers to the data latency property of eventual consistency being almost instantaneous. See Real time process have the highest priority They are generally passed over a websocket in dual...
Web - (Hot|Live) (Edit|Reload) - Auto File Sync

Live reloading (ie File sync) in the web means that the Browser automatically update/refresh the HTML page when you change files in your project (HTML, CSS, images, ...) Reload the page at interval:...
Browser Scripts Classed By Origin
Web Resource - Origin

The origin is a property of a resource that is used as the scope of privilege for scripts used by user agents (browser) The origin is calculated and set by the browser (ie client) on each resource from...
Web Service - API

A Web Api is generally a synonym for an API based on the HTTP protocol. See the Technology: REST. A HTTP request with the API request expressed in the URL properties, HTTP header and or HTTP body...



Share this page:
Follow us:
Task Runner