All Products
Search
Document Center

Edge Security Acceleration:Configure WebSocket

Last Updated:May 14, 2024

If you want your origin server to allow WebSocket requests whose URLs begin with ws:// or wss://, you need to enable the WebSocket feature on Dynamic Content Delivery Network (DCDN). Then, DCDN can communicate with the origin server over the WebSocket protocol to transmit and update data in real time.

Background information

WebSocket is a TCP-based protocol that implements persistent and full-duplex communications between a client and server and allows the server to actively send information to the client. Before the rise of WebSocket, web applications make inquiries for duplex communications by continuously sending HTTP requests. This results in low service efficiency and increased costs. However, WebSocket requires only one handshake between the client and server to establish a persistent connection and implement bi-directional data transmission. This saves server resources and bandwidth, and ensures communications in real time.

Scenarios

Scenario

Description

Live commenting

User A posts a comment from a mobile phone and wants to view live comments from other clients on the phone. To meet this requirement, WebSocket is used to push the live comments from other clients to the mobile phone of User A. User A can then view the live comments sent by other users.

Online education

On a one-to-many online education platform, WebSocket can be used to push the notes and syllabuses edited on the client of a teacher to the clients of students in real time.

Real-time quotes for financial products

The constantly changing stock and gold prices can be pushed to clients around the world in real time over the WebSocket protocol, which facilitates financial decision-making in trading.

Live sportscasts

Live sportscasts are the top concern of a large number of sports fans all over the world. WebSocket satisfies the requirements of these sports fans by providing real-time sports updates.

Video conferencing

Video conferencing is adopted in a wide range of scenarios. In a video conference, participants join the conference from multiple devices. WebSocket helps you deliver real-time information to these participants.

Location-aware applications

An increasing number of developers apply GPS capabilities of mobile devices to location-aware applications. Based on the physical location of users that is updated continuously, the location-aware applications can provide tailored offerings and information to users.

Usage notes

  • Because WebSocket is incompatible with the HTTP/2 feature, do not enable them at the same time. Otherwise, an error will be reported when you access a domain name.

  • WebSocket is only used for dynamic acceleration. WebSocket support is required for your origin server.

  • If you upgrade from Alibaba Cloud CDN or DCDN for a domain name, WebSocket is unavailable for the domain name. You must submit a ticket to change the organization to which the domain name belongs before you can enable WebSocket.

  • WebSocket traffic is billed separately. For more information, see Billing of WebSocket.

Configure WebSocket

Note

Before you configure WebSocket, make sure that HTTP/2 is disabled and dynamic acceleration is enabled. For more information, see Enable HTTP/2 and Configure acceleration rules.

  1. Log on to the DCDN console.

  2. In the left-side navigation pane, click Domain Names.

  3. On the Domain Names page, find the domain name that you want to manage and click Configure in the Actions column.

  4. In the left-side navigation tree of the domain name, click Websocket and turn on Websocket.

  5. Click Modify.

  6. In the Configure WebSocket dialog box, configure Connection Timeout Period and Back-to-Origin Protocol.

    Parameter

    Description

    Connection Timeout Period

    The timeout period of a DCDN WebSocket connection. If no messages are transmitted within the specified timeout period, the connection is closed by default.

    • Default value: 60.

    • Unit: seconds.

    • We recommend that you set the timeout period based on the following rule: A ≤ B ≤ C.

      • A: the timeout period of the clients.

      • B: the timeout period of DCDN.

      • C: the timeout period of the origin server.

    Back-to-Origin Protocol

    The protocol over which requests are redirected to the origin server.

    • Follow: DCDN uses the same protocol (HTTP or HTTPS) as the client to redirect requests to the origin server. For this option, port 443 or 80 of the origin server must be open.

    • HTTP: DCDN redirects requests to the origin server over HTTP.

    • HTTPS: DCDN redirects requests to the origin server over HTTPS. For this option, port 443 of the origin server must be open.

  7. Click OK.

FAQ

Can I offset WebSocket traffic consumed from an outbound traffic plan?

No. WebSocket traffic is billed separately. You can purchase a WebSocket data transfer plan to offset WebSocket traffic.

After I add a domain name to Alibaba Cloud CDN, a WebSocket request to this domain name fails. What do I do?

Alibaba Cloud CDN does not support WebSocket. If you want to use the WebSocket feature, try DCDN.