小程序的聊天功能需要实时通信;
- wx.connectSocket({
- url: 'wss://60.205.228.30:2346',
- })
- wx.onSocketOpen(function (res) {
- console.log('WebSocket连接已打开!')
- })
- wx.sendSocketMessage({
- data: 'msg'
- })
- wx.onSocketMessage(function (res) {
- console.log('收到服务器内容:' + res.data)
- })