LearnViz CompSci
Home / Learn / Computer Networks / WebSockets

Advanced Topic 43 of 50 Computer Networks

WebSockets

Persistent full-duplex channels between browser and server.

How it works

A WebSocket provides a persistent, full-duplex connection between a browser or client and a server over a single TCP connection. It starts as an HTTP request with an Upgrade header, after which both sides can send small framed messages at any time without repeated request overhead. Frames can carry text or binary data, with ping and pong frames for keep-alive and close frames to end the connection.

Step-by-step walkthrough

  1. The browser sends an HTTP request with Upgrade: websocket.
  2. The server agrees with 101 Switching Protocols.
  3. The connection stays open.
  4. Either side can now send messages at any time.
  5. It suits chat, live prices and games.

Where it is used

Chat applications, live dashboards, collaborative editing, multiplayer games, stock tickers and notifications use WebSockets.

Common pitfall

Long-lived connections consume server resources and complicate load balancing and scaling, since state is tied to a connection. Proxies and firewalls may drop idle connections, so use heartbeats and reconnection with backoff. Authenticate during the handshake and validate origins to prevent cross-site hijacking. For one-way updates, Server-Sent Events may be simpler.

Where it fits in the course

WebSockets is topic 43 of 50 in Computer Networks, rated Advanced. It follows QUIC and HTTP/3. The next topic is Software-Defined Networking.

Practice and explore

How to study this topic

  1. Read the explanation above and restate the definition in your own words.
  2. Open the interactive lesson and answer its mini quiz.
  3. Read the common pitfall, then write a short example that avoids it.
  4. Check your understanding in the Computer Networks quiz, and revisit the topic if you miss a question.

Frequently asked questions

What is WebSockets?
Persistent full-duplex channels between browser and server. It belongs to Computer Networks and is an advanced-level topic.
Where do people use WebSockets?
Chat applications, live dashboards, collaborative editing, multiplayer games, stock tickers and notifications use WebSockets.
What is the most common mistake with WebSockets?
Long-lived connections consume server resources and complicate load balancing and scaling, since state is tied to a connection.
What should I learn before this topic?
Start with QUIC and HTTP/3, the topic just before it in Computer Networks.
How can I practice it?
Answer the mini quiz in the interactive lesson, then take the Computer Networks quiz.
Is WebSockets hard to learn?
It is an Advanced topic. Expect to read the explanation more than once and to connect it with earlier topics. Working through a small example by hand helps most.
How long does it take to learn WebSockets?
Most learners can read the explanation and finish the interactive lesson in under an hour. Fluency comes from applying the idea, so plan a few short practice sessions with the quiz.
Which topics are related to WebSockets?
QUIC and HTTP/3, Software-Defined Networking, VPN are closely connected. The full list is in the related topics section of this page.
What should I study after WebSockets?
Continue with Software-Defined Networking, the next topic in Computer Networks.

Related topics