Sodda Hayotiy O'xshatish
"HTTP is like sending letters back and forth; WebSockets is an open telephone line where both parties can talk continuously."
Qanday ishlaydi va Nega kerak?
Unlike HTTP request-response cycles, WebSockets keep an open socket channel, allowing the server to push updates instantly without polling overhead.
Amaliy Kod Ko'rinishi
typescriptconst socket = new WebSocket("wss://thegogetters.uz/api/messages/stream");
socket.onmessage = (event) => {
const message = JSON.parse(event.data);
console.log("Yangi xabar:", message);
};Asosiy Xulosalar
Essential for instant messaging, collaborative canvas, and financial tickers
Ultra-low latency frame overhead (2-10 bytes)
Complementary to Server-Sent Events (SSE) for unidirectional streams