The WebSocket protocol simplifies data exchange between a client and a server by allowing the server to push data to the client. WebSocket increases the utilization of server and bandwidth resources and reduces latency. This topic describes how to enable and configure WebSocket.

Notice
  • By default, WebSocket is disabled. After you enable the WebSocket feature, the feature is displayed in the Dynamic Route for CDN (DCDN) console.

    If you want to enable WebSocket, submit a ticket.

  • WebSocket is used only for dynamic content delivery.
The following sections describe how to enable and use the WebSocket feature:

Apply to use WebSocket

Apply to use WebSocket: You can submit a ticket and apply to use WebSocket. Only enterprise users can apply to use WebSocket. You cannot enable WebSocket for domain names whose origin servers are deployed outside the Chinese mainland and whose acceleration region is set to Mainland China Only or Global.

Alibaba Cloud customer service reviews the application and notifies you of the result by text messages and emails within one business day. After your application is approved, you can enable WebSocket in the console.
Notice WebSocket is a value-added feature and is billed as an independent service. For more information about WebSocket billing, see DCDN Pricing.

Enable WebSocket

Note
Before you enable the WebSocket feature, make sure that the following requirements are met:
  • Your Alibaba Cloud account has passed real-name verification for enterprises, and a domain name that belongs to your Alibaba Cloud account has a valid Internet Content Provider (ICP) number.
  • HTTP/2 is disabled.

    If clients do not support HTTP/2, you must disable HTTP/2 for DCDN. Otherwise, service errors may occur. For more information, see Enable HTTP/2.

  1. Log on to the DCDN console.
  2. In the left-side navigation pane, click Domain Names.
  3. On the Configure page, find the domain name that you want to manage and click Domain Names in the Actions column.
  4. Optional:Turn on Dynamic Acceleration. If the feature is enabled, skip this step.
    1. In the left-side navigation pane of the domain name, click Acceleration Rules.
    2. Turn on Dynamic Acceleration.
      Enable dynamic content delivery
  5. In the left-side navigation pane of the domain name, click Websocket and turn on Websocket.
    Enable WebSocket
  6. Click Modify.
  7. In the Configure WebSocket dialog box, configure the Connection Timeout Period and Back-to-Origin Protocol parameters.
    Websocket
    Parameter Description
    Connection Timeout Period
    The timeout period is the interval at which the client sends data packets to the server to synchronize the current status.
    • 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.
    Note If the timeout period of the client is longer than that of the origin server, errors may occur.
    Back-to-Origin Protocol You can specify a 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. 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. Port 443 of the origin server must be open.
  8. Click OK.

Query bandwidth usage and HTTP status codes

After you configure and use WebSocket, click WebSocket in the left-side navigation pane in the DCDN console to go to the Websocket page. Then, you can view monitoring information about Bandwidth and HTTP CODE. WebSocket monitoring

Disable WebSocket

If you no longer want to use WebSocket, you can disable WebSocket in the DCDN console. The WebSocket is disabled immediately after you turn off the switch.