Configure WebSocket

更新时间:
复制 MD 格式

Enable the WebSocket feature in DCDN so that your origin server can handle ws:// or wss:// requests for real-time data transmission and updates.

Background

WebSocket is a TCP-based protocol that provides persistent, full-duplex communication between a client and a server, allowing the server to push data to the client at any time. Before WebSocket, two-way communication required continuous HTTP polling, which was inefficient and resource-intensive. With WebSocket, a single handshake establishes a persistent connection for bidirectional data transfer, saving server resources and bandwidth.

Use cases

Scenario

Description

Bullet comments

When a user sends a bullet comment, the server displays it on their screen along with comments from other users in real time.

Online education

In a one-to-many online class, the teacher's notes and outlines are pushed to multiple students' clients in real time.

Real-time quotes for financial products

Prices for stocks, gold, and other assets change rapidly. WebSocket pushes these updates to clients worldwide in real time, helping traders make quick decisions.

Live sports updates

Millions of fans follow live sports events. WebSocket delivers real-time score and event updates for a smooth viewing experience.

Video conferencing and chat

Video conferencing and chat applications require real-time data exchange between participants. WebSocket enables this continuous communication.

Location-based applications

Many applications use mobile GPS capabilities. If your app tracks a user's location continuously, for example, to record a running route, WebSocket lets you collect detailed position data in real time.

Considerations

  • The WebSocket protocol is not compatible with the Configure HTTP/2 feature. To prevent access errors for your domain name, do not enable both features at the same time.

  • WebSocket is for dynamic acceleration only, and your origin server must also support it.

  • If you upgraded your domain name from CDN to DCDN, you cannot enable the WebSocket feature directly. You must first fill out a form to request an architecture change for your domain name.

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

  • To adjust the WebSocket connection timeout, configure the Origin request timeout feature.

Configure WebSocket

Note

Before you configure WebSocket, ensure you have disabled the Configure HTTP/2 feature and enabled Dynamic Acceleration.

  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 pane for the domain name, click WebSocket and turn on the WebSocket switch.

  5. Click Modify.

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

    Parameter

    Description

    Connection Timeout Period

    The timeout period for a WebSocket connection on the DCDN platform. If no data is transmitted within this period, DCDN closes the connection.

    • Default value: 60.

    • Unit: seconds.

    • Recommended configuration: A <= B <= C.

      • A: Client connection timeout.

      • B: DCDN platform connection timeout.

      • C: Origin server connection timeout.

    Back-to-Origin Protocol

    The protocol that DCDN uses to request resources from your origin server.

    • Follow: The origin request protocol matches the client request protocol (HTTP or HTTPS). Your origin server must support port 80 or 443.

    • HTTP: DCDN uses HTTP for origin requests.

    • HTTPS: DCDN uses HTTPS for origin requests. Your origin server must support port 443.

  7. Click OK.

FAQ

WebSocket traffic offset

No. WebSocket is billed separately. You can purchase a WebSocket traffic resource pack to offset the charges.

CDN and WebSocket connection

CDN does not support the WebSocket protocol, but DCDN does. To use WebSocket, you must use DCDN.