# wx.closeSocket(Object object)

Disables the WebSocket connection

# Parameters

# Object object

Attribute Type Default Required Description
code number 1000 (indicating that the connection is disabled normally) No A numeric value indicates the status code explaining why the connection has been disabled.
reason string No A readable string explaining why the connection has been disabled. This string must be a UTF-8-encoded text (not characters) with not more than 123 bytes.
success function No The callback function for a successful API call
fail function No Callback function for failed API call
complete function No Callback function used when API call completed (always executed whether call succeeds or fails)

# Sample Code

wx.connectSocket({
  url: 'test.php'
})

//Pay attention to the operation sequence
//If you call  wx.closeSocket before the  wx.onSocketOpen callback for  wx.connectSocket ,  WebSocket  connection cannot be disabled.
//You can only call wx.closeSocket to disable the connection when WebSocket is enabled.
wx.onSocketOpen(function() {
  wx.closeSocket()
})

wx.onSocketClose(function(res) {
  console.log('WebSocket Disabled!')
})