5银子
这是我接收的方法:
btyearray 的length 始终为0 。
private onReceiveMessage(evt : egret.ProgressEvent):void{
console.log('ProgressEvent.SOCKET_DATA');
let btyearray: egret.ByteArray = new egret.ByteArray();
btyearray.endian = egret.Endian.LITTLE_ENDIAN;
btyearray.position = 0;
this._websocket.readBytes(btyearray);
btyearray.position = 0;
需要指出的是 :
this._websocket = new egret.WebSocket();
this._websocket.type = egret.WebSocket.TYPE_BINARY;
//添加收到数据侦听,收到数据会调用此方法
this._websocket.addEventListener(egret.ProgressEvent.SOCKET_DATA,this.onReceiveMessage, this);
//添加链接打开侦听,连接成功会调用此方法
this._websocket.addEventListener(egret.Event.CONNECT, this.onSocketOpen, this);
//添加链接关闭侦听,手动关闭或者服务器关闭连接会调用此方法
this._websocket.addEventListener(egret.Event.CLOSE, this.onSocketClose, this);
//添加异常侦听,出现异常会调用此方法
this._websocket.addEventListener(egret.IOErrorEvent.IO_ERROR, this.onSocketError, this);
问题是 :
this._websocket.readBytes(btyearray); 后 , btyearray的length为0 , 无法取到数据。 Egret能发数据 , 后端能够取到 ; 但是后端发过来的数据 ,Egret WebSocket 始终得不到数据 , 为什么 ?????请各位大神解答
|
|