webSocket 手机端连接不上, 开发者工具正常
webSocket, 电脑端正常, 手机端发送数据报错 SocketTask.send:fail SocketTask.readState is not OPEN 代码如下 [代码]wxonopen();[代码][代码]function[代码] [代码]wxonopen(){[代码][代码]ws = wx.connectSocket({[代码][代码]url: url2,[代码][代码]success: [代码][代码]function[代码] [代码]() {[代码][代码]console.log([代码][代码]'wx.connectSocket成功'[代码][代码]);[代码][代码]},[代码][代码]fail: [代码][代码]function[代码][代码](err) {[代码][代码]if[代码] [代码](err) {[代码][代码]console.log([代码][代码]'###### wx.connectSocket连接失败'[代码][代码], err)[代码][代码]app.globalData.socketConnectFail = [代码][代码]true[代码] [代码]// 定义一个全局变量,当链接失败时改变变量的值[代码][代码]}[代码][代码]},[代码][代码]complete: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]console.log([代码][代码]'wx.connectSocket完成'[代码][代码]);[代码][代码] [代码][代码]Laya.timer.loop(3000,[代码][代码]this[代码][代码],clfun);[代码][代码] [代码][代码]function[代码] [代码]clfun(){[代码][代码] [代码][代码]if[代码][代码](isOpen){[代码][代码] [代码][代码]// wx.exitMiniProgram({[代码][代码] [代码][代码]// success: function (data) {[代码][代码] [代码][代码]// console.log("退出成功");[代码][代码] [代码][代码]// },[代码][代码] [代码][代码]// fail: function (data) {[代码][代码] [代码][代码]// console.log("退出失败");[代码][代码] [代码][代码]// }[代码][代码] [代码][代码]// })[代码][代码] [代码][代码]isOpen = [代码][代码]false[代码][代码];[代码][代码] [代码][代码]wxonopen();[代码][代码] [代码][代码]node();[代码][代码] [代码][代码]}[代码][代码]else[代码][代码]{[代码][代码] [代码][代码]ws.send({[代码][代码] [代码][代码]data: JSON.stringify({ msg: [代码][代码]"发送消息"[代码][代码],}),[代码][代码] [代码][代码]success: [代码][代码]function[代码][代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]"发送消息成功"[代码][代码]);[代码][代码] [代码][代码]console.log(res);[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: [代码][代码]function[代码][代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]"发送消息失败"[代码][代码]);[代码][代码] [代码][代码]console.log(res);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]});[代码][代码] [代码][代码]}[代码][代码] [代码] [代码] [代码][代码]}[代码][代码]}[代码][代码]})[代码]