收藏
回答

cocos 发微信小游戏 用websocket send 发送数据给后台数据失败

框架类型 问题类型 操作系统 工具版本
小游戏 Bug Windows 3.4.3

我在cocos,socket链接成功,要发个int32,在开发者工具能发送成功,手机端无论ios或者安卓都不能发送出去

 if (this.isConnect()) {

            console.log("发送服务器ID:" + this._socket.url);

            let binary = new Int32Array(new ArrayBuffer(32));

            binary[0] = serverId;

            this._socket.send(binary);

        }

        else {

            console.log("发送服务器ID的时候还没连上:");

        }



回答关注问题邀请回答
收藏

2 个回答

  • 稻草人
    稻草人
    03-01

    我也遇到这个问题,开发者工具能发送成功,网页也成功,微信小游戏真机不行:

        send(buf:Buffer){
            if (this.websocket == undefined) 
            {
                console.error('this.websocket is undefined')
                return
            }
                
            this.websocket.send(buf.buffer)//这样可以发
            //this.websocket.send(buf)  这样好像微信小游戏真机发不出任何消息(微信开发者工具发送成功,网页也成功),原因不明
        }
    


    03-01
    有用
    回复
  • 左+
    左+
    2024-06-13

    同样遇到这个问题,请问楼主咋解决的,求教!!!

    2024-06-13
    有用
    回复
登录 后发表内容