Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 88776

websocket在IOS下主动调用close方法关闭不掉

$
0
0

@406214349 写道:

  • Creator 版本:2.2.1

  • 目标平台: IOS

websocket在IOS下主动调用close方法关闭不掉连接,服务器端也收不到关闭命令,安卓和web都能正常关闭;

  • 重现步骤:在切后台onHide中主动关闭连接,在切会前台onShow中重新连接,发现在onHide中close的连接没有关闭掉,服务器端也收不到关闭命令,并且只有在IOS中才会出现。打印的this.socket.readyState一直是1,表示连接中。
    主要代码如下:

`

 start() {
    this.connect();
    let self = this;

    wx.onShow(function () {
        console.warn("onshow");
        self.connect();
    }.bind(self));

    wx.onHide(() => {
        console.warn("onhide");
        self.socket.close()
        console.warn("当前ws状态:", this.socket.readyState);
    })
}


connect() {
    this.stop();
    this.socket && this.socket.close();
    let url = xxx;
    this.socket = wx.connectSocket({ url: url });
    console.log("this.socket", this.socket);
    this.socket.onOpen((e) => { console.log("wssssss open", e) });
    this.socket.onMessage((e) => { console.log("wsssss onmessage", e) });
    this.socket.onClose((e) => { console.warn("wsssss close", e) });
    this.socket.onError((e) => { console.warn("wsssss error", e) });
}`

帖子: 1

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 88776

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>