[]socket与node服务端连不上?按照官方案例
//初始化引擎输出:出错-关闭
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.connectByUrl("ws://45.78.**.**:3000");
this.socket.on(Laya.Event.OPEN, this, openHandler);
this.socket.on(Laya.Event.MESSAGE, this, receiveHandler);
this.socket.on(Laya.Event.CLOSE, this, closeHandler);
this.socket.on(Laya.Event.ERROR, this, errorHandler);
function openHandler(event){
//正确建立连接;
console.log("链接");
}
function receiveHandler(msg){
///接收到数据触发函数
console.log("接受");
}
function closeHandler(e){
//关闭事件
console.log("关闭");
}
function errorHandler(e){
//连接出错
console.log("出错");
}
有哪里写的不对,node端是好的,用web客户端可以连上的
没有找到相关结果
已邀请:
要回复问题请先登录
2 个回复
Aar0n
赞同来自:
寻寻觅觅
赞同来自: