微信小程序建立WebSocket后不触发onSocketOpen
发布于 5 年前 作者 weijun 16643 次浏览 来自 问答

建立连接后成功,进入成功回调,但是onSocketOpen和onSocketMessage都不打印,求解,代码如下:

onLoad: function (options) {

    wx.connectSocket({

        url: ‘ws://xxx.xx.xxx:80xx/xxx/websocket/’,

        data: {},

        header: {

            ‘content-type’: ‘application/json’

        },

        method: ‘GET’,

        success: function (socketRes) {

            console.log('connect success: ', socketRes);

        },

        fail: function (err) {

            console.log('connect error: ', err)

        }

    });

    

    wx.onSocketOpen(function (res) {

        console.log(‘WebSocket连接已打开!’)

    })

    

    wx.onSocketMessage(function (res) {

        console.log(‘收到服务器内容:’ + res.data)

    })

}

5 回复

Socket连接失败,报错如下:java.security.cert.CertPathValidatorException:Trust anchor for certification path not found

监听出来就是这个错误:

com.android.org.bouncycastle.jce.exception.ExtCertPathValidatorException: Could not validate certificate: Certificate expired at Sun Feb 18 07:59:59 GMT+08:00 2018 (compared to Sat Mar 03 09:49:20 GMT+08:00 2018)

我是连接成功,onSocketOpen和onSocketError都没调用,不知道怎么回事?

请检查是否连接建立失败了,可以用 wx.onSocketError 监听错误事件

com.android.org.bouncycastle.jce.exception.ExtCertPathValidatorException: Could not validate certificate: Certificate expired at Sun Feb 18 07:59:59 GMT+08:00 2018 (compared to Sat Mar 03 09:49:20 GMT+08:00 2018)

我也是出现这种情况

回到顶部