本地调试websocket 调用没有反应?
//开启websocket
openSocket:function(){
//申请
wx.connectSocket({
url: ‘http://localhost:8080/chanxiu\_v04/chat’,
data:‘need help’,
header: {
‘content-type’: ‘application/json’
},
success:function(res){
console.log(“调用wx.connectSocket成功”);
},
fail:function(res){
console.log(“调用wx.connectSocket失败:\n”+res.data);
}
});
//成功连接
wx.onSocketOpen(function(res){
console.log(“调用wx.onSocketOpen成功”);
});
//链接失败
wx.onSocketError(function (res) {
console.log(‘WebSocket连接打开失败,请检查!’)
})
},
//发送消息
sendMessage:function(){
wx.sendSocketMessage({
data: ‘i need money,can you give me some?’
})
},
//关闭连接
closeSocket:function(){
wx.closeSocket({
code: 0,
reason: ‘thanks’,
success: function (res) { },
fail: function (res) { },
complete: function (res) { },
});
//监听是否关闭
wx.onSocketClose(function (res) {
console.log(‘WebSocket 已关闭!’)
})
}
})
点击哪一个function,都不报任何 log 信息和其他信息?请教大神
