This topic provides an overview of WebSocket and WebSocket Secure.
What is WebSocket?
WebSocket is an HTML5 protocol that implements full-duplex communication between browsers and servers. WebSocket allows you to establish real-time communication and save server and bandwidth resources. WebSocket is similar to HTTP, which transfers data over TCP. One major difference between WebSocket and HTTP is that WebSocket is a two-way communication protocol. After a connection is established over WebSocket, the WebSocket server and the browser or client can send or receive data between each other, similar to a socket. The WebSocket server and the client must complete a handshake, similar to a TCP handshake, to establish communication.
WebSocket Secure is the encrypted version of WebSocket.
Why WebSocket?
New web applications emerge as the Internet develops. These applications, such as live video streaming and online chat rooms, require servers to push messages in real time. To achieve this goal, a large number of websites used the polling technique in the past. When the polling technique is used, the browser sends HTTP requests to the server at specific intervals, such as every second. Then, the server returns the most recent data to the browser of the client. One disadvantage of this technique is that bandwidth resources are wasted. The browser must constantly send requests to the server, and the HTTP request header is long and contains only a small amount of valid data.
To solve this problem, HTML5 defines WebSocket, which helps save server and bandwidth resources and facilitates real-time communication. WebSocket enables full-duplex communication between the browser and the server, and allows the server to proactively send data to the client.
The following figure shows how a client interacts with a server by using WebSocket.
How do I enable WebSocket and WebSocket Secure for a Server Load Balancer (SLB) instance?
By default, HTTP listeners support WebSocket.
By default, HTTPS listeners support WebSocket Secure.
Supported regions
WebSocket and WebSocket Secure are available in all regions.
Billing
You are not charged for using WebSocket or WebSocket Secure.
Limits
Take note of the following limits when you use WebSocket and WebSocket Secure:
If the services on backend Elastic Compute Service (ECS) instances communicate with the SLB instance over HTTP/1.1, we recommend that you deploy web servers that support HTTP/1.1 on the backend ECS instances.
If no packet is transmitted between an SLB instance and a backend service on an ECS instance for 60 seconds, the connection is closed. If you want the connection to remain open, enable the keepalive feature to ensure that a packet is transmitted every 60 seconds.