Announcement: Tencent Cloud Mini Program Platform Renamed to Tencent Cloud Super App as a Service on January 2, 2025
Console Updates
Android SDK Updates
iOS SDK Updates
Flutter SDK Updates
IDE Updates
Base Library Updates
This method is used via TCPSocket.bindWifi(Object options).
Attribute | Type | Default value | Required | Note |
BSSID | string | - | Yes | The BSSID of the current Wi-Fi network, which can be obtained through wx.getConnectedWifi. |
const tcp = wx.createTCPSocket()tcp.bindWifi({ BSSID: 'xxx' })tcp.onBindWifi(() => {})
This method is used via TCPSocket.close().
const tcp = wx.createTCPSocket()tcp.close()
This method is used via TCPSocket.connect(Object options).
Attribute | Type | Default value | Required | Note |
address | string | - | Yes | The address to which the socket is to be connected. |
Port No. | number | - | Yes | The port to which the socket is to be connected. |
timeout | number | 2 | No | The timeout duration for the socket connection, defaulting to 2 seconds. |
const tcp = wx.createTCPSocket()tcp.connect({address: '192.168.193.2', port: 8848})
This method is used via TCPSocket.onClose(function listener).
This method is used via TCPSocket.offClose(function listener).
const listener = function (res) { console.log(res) }TCPSocket.onConnect(listener)TCPSocket.offConnect(listener) // The same function object as the listener must be passed in.
This method is used via TCPSocket.onConnect(function listener).
This method is used via TCPSocket.offConnect(function listener).
const listener = function (res) { console.log(res) }TCPSocket.onConnect(listener)TCPSocket.offConnect(listener) // The same function object as the listener must be passed in.
This method is used via TCPSocket.onError(function listener).
Attribute | Type | Note |
errMsg | string | Error Message |
This method is used via TCPSocket.offError(function listener).
const listener = function (res) { console.log(res) }TCPSocket.onError(listener)TCPSocket.offError(listener) // The same function object as the listener must be passed in.
This method is used via TCPSocket.onMessage(function listener).
Attribute | Type | Note |
message | ArrayBufffer | Received message |
remoteInfo | Object | Sender's address information |
localInfo | Object | Recipient's address information |
Structure attributes | Type | Note |
address | string | The address of the socket sending the message |
family | string | The protocol family in use, either IPv4 or IPv6. |
Port No. | number | Port No. |
size | number | The size of the message, measured in bytes. |
Structure attributes | Type | Note |
address | string | The address of the socket sending the message |
family | string | The protocol family in use, either IPv4 or IPv6. |
Port No. | number | Port No. |
This method is used via TCPSocket.offMessage(function listener).
const listener = function (res) { console.log(res) }TCPSocket.onMessage(listener)TCPSocket.offMessage(listener) // The same function object as the listener must be passed in.
This method is used via TCPSocket.onBindWifi(function listener).
This method is used via TCPSocket.offBindWifi(function listener).
const listener = function (res) { console.log(res) }TCPSocket.onBindWifi(listener)TCPSocket.offBindWifi(listener) // The same function object as the listener must be passed in.
This method is used via TCPSocket.write(string|ArrayBuffer data).
const tcp = wx.createTCPSocket()tcp.write('hello, how are you')
Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback