你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
输入关键字进行搜索
搜索:
发现
话题
全文搜索
登录
[]Laya.Socket 是不是不支持Safari浏览器二进制格式的数据传输?
Laya.Socket 是不是不支持Safari浏览器二进制格式的数据传输?
使用二进制传输 后端收到的竟然是 [object ArrayBuffer] 纯文本,其他浏览器测试正常.
没有找到相关结果
已邀请:
与内容相关的链接
提交
2 个回复
wudi199553
赞同来自:
你提供一个例子过来把,我们没有接到别的开发者,类似的情况反馈
hh821207
赞同来自:
就是按照官方例子来做的测试
/*
* name;
*/
class Test{
private socket: Laya.Socket;
private byte: Laya.Byte;
constructor() {
//初始化引擎
Laya.init(600, 400, Laya.WebGL);
this.byte = new Laya.Byte();
//这里我们采用小端
this.byte.endian = Laya.Byte.LITTLE_ENDIAN;
this.socket = new Laya.Socket();
//这里我们采用小端
this.socket.endian = Laya.Byte.LITTLE_ENDIAN;
//建立连接
this.socket.connect("localhost", 9244);
// this.socket.connectByUrl("ws://localhost:9241");
// this.socket.connectByUrl("ws://localhost:8989");
this.socket.on(Laya.Event.OPEN, this, this.openHandler);
this.socket.on(Laya.Event.MESSAGE, this, this.receiveHandler);
this.socket.on(Laya.Event.CLOSE, this, this.closeHandler);
this.socket.on(Laya.Event.ERROR, this, this.errorHandler);
}
private openHandler(event: any = null): void {
//正确建立连接;
this.byte.writeByte(1);//写入一个字节
this.byte.writeInt16(20);//写入一个int16的数据
this.byte.writeFloat32(20.5);//写入一个32位的浮点数据
this.byte.writeUTFString("hello");// 写入一个字符串
var by:Laya.Byte = new Laya.Byte();//这里声明一个临时Byte类型
by.endian = Laya.Byte.LITTLE_ENDIAN;//设置endian;
by.writeInt32(5000);//写入一个int32数据
by.writeUint16(16);//写入一个uint16 数据
this.byte.writeArrayBuffer(by.buffer);//把临时字节数据的数据写入byte中,这里注意写入的是by.buffer;
this.socket.send(this.byte.buffer);//这里是把字节数组的数据通过socket发送给服务器。
this.byte.clear();//清除掉数据;方便下次读写;
}
private receiveHandler(msg: any = null): void {
///接收到数据触发函数
// this.socket.send("!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
private closeHandler(e: any = null): void {
//关闭事件
// this.socket.send("!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
private errorHandler(e: any = null): void {
//连接出错
// this.socket.send("!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
}
new Test();
这是使用google浏览器发送到后台,后台获取的数据,乱码是因为直接转成的字符串,实际取是正确的
这是使用safair浏览器发送到后台,后台获取的数据,转成的字符串,就是乱码是“[object ArrayBuffer]”纯文本
要回复问题请先
登录
发起人
hh821207
相关问题
iphone自带浏览器页面怎么锁定
谷歌浏览器播放mp3出现The AudioContext was not allowed to start.
请问下loader如何强制加载一个文件,避免浏览器的缓存
用Mac下Unity5.6.2f1导出的模型在Mac浏览器显示正常,发布到移动端不显示模型,但是顶点数面数都有
打包QQ小游戏,rayCast发出的射线检测到的物体与点击的不一致,在浏览器和微信小游戏没有这种情况发生
Layabox 在最新的mac系统中safari中显示错乱
我的tieldmap生成的json文件里data是这种格式,地图显示有误
不带格式后缀的图片无法成功加载
怎样获取浏览器地址传过来的GET参数
华为mate60系列手机在微信浏览器打开Laya2.x版本游戏会闪屏
laya.d3.utils.Utils3D的convert3DCoordTo2DScreenCoord这个接口api描述是不是错了?
问题状态
最新活动:
2017-11-29 17:40
浏览:
2168
关注:
2
人
商务合作
2 个回复
wudi199553
赞同来自:
hh821207
赞同来自:
/*
* name;
*/
class Test{
private socket: Laya.Socket;
private byte: Laya.Byte;
constructor() {
//初始化引擎
Laya.init(600, 400, Laya.WebGL);
this.byte = new Laya.Byte();
//这里我们采用小端
this.byte.endian = Laya.Byte.LITTLE_ENDIAN;
this.socket = new Laya.Socket();
//这里我们采用小端
this.socket.endian = Laya.Byte.LITTLE_ENDIAN;
//建立连接
this.socket.connect("localhost", 9244);
// this.socket.connectByUrl("ws://localhost:9241");
// this.socket.connectByUrl("ws://localhost:8989");
this.socket.on(Laya.Event.OPEN, this, this.openHandler);
this.socket.on(Laya.Event.MESSAGE, this, this.receiveHandler);
this.socket.on(Laya.Event.CLOSE, this, this.closeHandler);
this.socket.on(Laya.Event.ERROR, this, this.errorHandler);
}
private openHandler(event: any = null): void {
//正确建立连接;
this.byte.writeByte(1);//写入一个字节
this.byte.writeInt16(20);//写入一个int16的数据
this.byte.writeFloat32(20.5);//写入一个32位的浮点数据
this.byte.writeUTFString("hello");// 写入一个字符串
var by:Laya.Byte = new Laya.Byte();//这里声明一个临时Byte类型
by.endian = Laya.Byte.LITTLE_ENDIAN;//设置endian;
by.writeInt32(5000);//写入一个int32数据
by.writeUint16(16);//写入一个uint16 数据
this.byte.writeArrayBuffer(by.buffer);//把临时字节数据的数据写入byte中,这里注意写入的是by.buffer;
this.socket.send(this.byte.buffer);//这里是把字节数组的数据通过socket发送给服务器。
this.byte.clear();//清除掉数据;方便下次读写;
}
private receiveHandler(msg: any = null): void {
///接收到数据触发函数
// this.socket.send("!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
private closeHandler(e: any = null): void {
//关闭事件
// this.socket.send("!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
private errorHandler(e: any = null): void {
//连接出错
// this.socket.send("!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
}
new Test();
这是使用google浏览器发送到后台,后台获取的数据,乱码是因为直接转成的字符串,实际取是正确的
这是使用safair浏览器发送到后台,后台获取的数据,转成的字符串,就是乱码是“[object ArrayBuffer]”纯文本