# SocketTask wx.connectSocket(Object object)

Creates a WebSocket connection. Read related instructions before use.

# Parameters

# Object object

Property Type Default Value Required Description Minimum Version
url string Yes The wss API URL of developer server
header Object No HTTP Header. Referer is not available in Header.
protocols Array.<string> No Sub-protocol array 1.4.0
tcpNoDelay boolean false No TCP_NODELAY settings when a TCP connection is established 2.4.0
success function No The callback function for a successful API call
fail function No The callback function for a failed API call
complete function No The callback function used when the API call completed (always executed whether the call succeeds or fails)

# Return Values

# SocketTask

Start from base library version 1.7.0. Please remaining backward compatible.

WebSocket task

# Number of Concurrent Connections

  • In version 1.7.0 or later, up to 5 WebSocket connections can exist at the same time.
  • Before version 1.7.0, a Mini Program can only have one WebSocket connection at a time. If a WebSocket connection already exists, it will be automatically disabled and a new one will be created.

# Sample Code

wx.connectSocket({
  url: 'wss://example.qq.com',
  header:{
    'content-type': 'application/json'
  },
  protocols: ['protocol1'],
  method:"GET"
})
点击咨询小助手