# SocketTask wx.connectSocket(Object object)

with Promise style call: Not supported

Mini Program plugin: Support, need to Mini Program base library version no less than 1.9.6

Create a WebSocket Connect. Please read carefully before usingRelated notesRecommended use SocketTask The way to manage webSocket Link, the life cycle of each link is more controllable. There are multiple simultaneous webSocket In the case of links to wx Prefixes may bring up some of the situations that are not expected.

# parameter

# Object object

attribute type Default values Required Introductions Minimum version
url string yes Developer Server wss Interface address
header Object no HTTP Header,Header Can not be set Refer
protocols Array.&ltstring&gt no Subprotocol array 1.4.0
tcpNoDelay boolean false no establish TCP At the time of the connection. TCP_NODELAY Set up 2.4.0
perMessageDeflate boolean false no Enable compression expansion 2.8.0
timeout number no Timeout in milliseconds 2.10.0
success function no Interface calls the successful callback function
fail function no Interface calls failed callback functions
complete function no Callback function at the end of an interface call (both successful and unsuccessful calls are executed)

# Return value

# SocketTask

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

WebSocket quest

# Concurrency number

  • 1.7.0 And above versions can exist at most 5 individual WebSocket Connect.
  • 1.7.0 In the following versions, a Mini Program can only have one WebSocket Connection, if one currently exists WebSocket Connection, automatically closes the connection and recreates a WebSocket Connect.

# sample code

wx.connectSocket({
  url: 'wss://example.qq.com'
  header:{
    'content-type': 'application/json'
  },
  protocols: ['protocol1']
})