WebSocket

वेब

परिभाषा

एक संचार प्रोटोकॉल जो एकल TCP कनेक्शन पर ब्राउज़र और सर्वर के बीच फुल-डुप्लेक्स, स्थायी कनेक्शन प्रदान करता है। चैट, लाइव डैशबोर्ड और मल्टीप्लेयर गेम जैसे रियल-टाइम एप्लिकेशन के लिए आदर्श।

From HTTP Upgrade to Full-Duplex

A WebSocket connection starts as a normal HTTPHypertext Transfer Protocol. The application-layer protocol for transmitting web pages, APIs, and other resources. HTTP defines methods (GET, POST, PUT, DELETE) and status codes for client-server communication. request with an Upgrade: websocket header. The server responds with 101 Switching Protocols, and from that point the underlying TCPTransmission Control Protocol. A reliable, connection-oriented transport protocol that guarantees ordered, error-checked delivery of data through three-way handshakes, acknowledgments, and retransmission. The foundation of HTTP, SSH, and most internet services. connection is repurposed as a persistent, full-duplex channel. Both sides can send frames at any time without waiting for the other to request. This contrasts sharply with HTTP request-response, where the server can only respond, never initiate.

When to Use WebSocket vs. REST

REST APIRepresentational State Transfer Application Programming Interface. An architectural style for web services that uses standard HTTP methods (GET, POST, PUT, DELETE) and stateless communication to manipulate resources identified by URLs. over HTTPSHTTP Secure. The encrypted version of HTTP that uses TLS to protect data in transit between a browser and a web server. Identified by the padlock icon in browsers and the https:// URL scheme. is appropriate for operations that naturally fit the request-response model: fetching a resource, submitting a form, running a query. WebSocket shines where low-latency server-push is required: live financial tickers, multiplayer game state, collaborative document editing, real-time monitoring dashboards. The persistent connection eliminates the overhead of TCP handshakes and SSL/TLSSecure Sockets Layer / Transport Layer Security. Cryptographic protocols that provide encrypted, authenticated communication over a network. SSL is deprecated; modern implementations use TLS 1.2 or TLS 1.3. renegotiation for every message, dramatically reducing LatencyThe time delay for a data packet to travel from source to destination, typically measured in milliseconds (ms). Lower latency is critical for real-time applications like video calls, gaming, and financial trading. for high-frequency updates.

Infrastructure Considerations

WebSocket connections are long-lived, which creates challenges for Load BalancerA device or service that distributes incoming network traffic across multiple backend servers to ensure no single server is overwhelmed. Improves availability, reliability, and scalability of web applications. configuration. Layer 4 load balancers handle them naturally since they forward raw TCP. Layer 7 load balancers must be explicitly configured to pass the Upgrade header and not close idle connections prematurely. Reverse ProxyA server that sits in front of backend servers, forwarding client requests and returning responses on their behalf. Used for SSL termination, load balancing, caching, and hiding the origin server's identity. servers like Nginx require increased proxy_read_timeout and proxy_http_version 1.1 to support WebSocket correctly. CDNContent Delivery Network. A geographically distributed network of servers that caches and serves content from locations close to end users, reducing latency and improving load times. Major providers include Cloudflare, AWS CloudFront, and Akamai. layers that cache HTTP responses must be bypassed entirely for WebSocket endpoints.

संबंधित शब्द

वेब में और अधिक