Urgent.News

What's breaking now, across thousands of outlets.

Tech

WebSockets Explained: Real-Time Data Without Polling

A customer adds a ceramic mug to their basket on a small shop's website, then waits. The order page says Processing, and nothing changes until they refresh. The server knew the order shipped ten minutes ago, but the page had no way of hearing about it. The usual fix is polling: the page asks the server "anything new?" every few seconds. Most of those requests get the answer "no", yet each one…

WebSockets are a technology that enables real-time, two-way communication between a web page and a server. Unlike traditional HTTP requests, which require the client to continually poll the server for updates, WebSockets establish a persistent connection that allows the server to push data to the client whenever it changes. This can greatly improve the user experience by reducing latency and conserving bandwidth.

However, WebSockets are not always the best solution. Before implementing them, it is important to consider several factors. First, each open WebSocket connection consumes server resources, so a large number of idle connections can be wasteful. Second, the network path between the client and server may not support long-lived connections, as some corporate proxies and older load balancers may drop or block them.

Third, when a WebSocket connection is lost, the client must handle the event and attempt to reconnect, as the browser does not automatically do so. Finally, security is a concern - WebSockets should always be used over a secure connection (wss) and the login credentials should be verified during the initial handshake, not in subsequent messages.

The article provides a practical example of a price ticker application using WebSockets. In this case, the server pushes price updates to the client every half second, allowing the dashboard to display the latest prices in real-time. The server is implemented using Node.js and the ws package, a popular WebSocket library for Node.

The client, written in JavaScript, connects to the WebSocket server, subscribes to the price updates, and logs each update as it arrives. The article demonstrates how to build a simple application using WebSockets, but cautions that they may not be the optimal choice for every use case.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Every Scheduled Task Was Refused for 70 Hours. My Watchdog Was One of Them.

A field note from the autonomous Claude Code agent I run every day on one Windows PC. The numbers come from its own ledgers, not from memory.

  • GPU driver error caused 70-hour refusal of all scheduled tasks
  • Watchdog process implemented to monitor system continuously
  • Machine rebooted on November 6, restoring scheduled tasks

gRPC Explained: APIs That Speak in Binary

A shop dashboard needs one thing from the orders service: the details of order 1042. Over plain JSON the request is easy to write and easy to break.

  • gRPC is a protocol for building APIs that communicate in binary format.
  • It uses a .proto file contract to define services, methods, and messages.
  • gRPC operates over HTTP/2, enabling streaming and shared connections.

More from Saturday 7 November →