

You need to serve assets to your users over HTTP, but you also need to provide them with streams for bi-directional messaging. Your users can be any type of client, like a web browser, mobile app, IoT device, Node.js client, or anything that knows TCP. Let’s say you need to write a server application, and you chose Node.js as your programming language. Let’s go over some basic socket and WebSocket programming with Node.js.

Similar functionality can be implemented using HTTP Long Polling or using a service like PubNub. WebSockets create a TCP socket connection between multiple devices or processes. When Should I Write WebSocket Programming Code?īesides a real-time stock or cryptocurrency tracker app, other common real-time use cases for WebSockets are: This pattern is far superior to HTTP request-response when an application requires systems to get the latest data ASAP. WebSockets create a full-duplex connection for sending messages from client to server, or server to client at any instant. WebSocket is its own layer 7 protocol, similar to HTTP. The faster a user learns about a stock price’s change, the faster they can react, and execute a buy or sell order. Imagine an app user interface where you see real-time stock prices. WebSockets are an excellent technology selection when you are designing your real-time app.
