Creator version?(版本号)
cocos creator v2.01
Affected platform?(受影响的平台)
Android
How to reproduce?(如何重现)
只要使用wss协议来连接的Android包每次都会出现,但是如果改为用ws协议来连的Android包是没有问题的。
PS:服务器是支持wss及ws的,打微信小程序包以及Web包是都是没有问题的。
JavaScript output or error produced?(报错信息和调用栈)
没有特别的报错,就是连接websocket的时候直接报onerror的连接错误
Demo project?(demo 项目)
cc.Class({
extends: cc.Component,
properties: {
label: {
default: null,
type: cc.Label
},
text: 'Hello, World!',
websocket:null,
wsServer:null,
},
onLoad: function () {
this.label.string = this.text;
var aa = 'aa.bb.com:7066/?token=NjNlZXFneTNqQ3JuUThtZTR5T3ZSVFZqRFpBQ2x1L0ZaOGd4cmpoM3hmNSggfdsgdfgfd';
this.init(aa);
},
init:function(wss){
this.wsServer = "ws://"+wss;
console.log("init连接地址",this.wsServer);
//创建websocket事件
this.websocket = new WebSocket(this.wsServer);
this.websocket.binaryType="arraybuffer";
//打开websocket连接
this.websocket.onopen = function (evt) {
console.log("websocket.onopen OK");
}.bind(this);
//关闭连接
this.websocket.onclose = function (evt) {
console.log("websocket.onclose",evt);
}.bind(this);
//监听信息的接收
this.websocket.onmessage = function (evt) {
console.log("返回的数据:",evt.data);
};
//监听websocket出错
this.websocket.onerror = function (evt) {
console.log("websocket.onerror",evt);
}
},
// called every frame
update: function (dt) {
},
});
在Cocos Creator v2.01 的 Android 应用中,使用 wss 协议连接 WebSocket 时遇到问题,而切换到 ws 协议则正常工作。服务器支持 wss 和 ws,且在微信小程序和 Web 平台运行无误。错误表现为连接 WebSocket 时直接触发 onerror 事件,但无具体错误信息。
777

被折叠的 条评论
为什么被折叠?



