学习socket.io重连api时,浏览器未打印重连日志
发布于 3 年前 作者 zhangyou1010 4116 次浏览 来自 问答

请教下各位,学习socket.io重连api时,浏览器未打印重连日志: 客户端代码如下:

<body>
    <p>Open up your developer console, kill your server and let the fun begin!</p>
    <script src="/socket.io/socket.io.js"></script>
    <script>
        var socket = io('http://localhost:5000', {
            'reconnection': true,
            'reconnectionDelay': 500,
            'reconnectionAttempts': 5
        });

        socket.on('reconnect', function (number) {
            console.info('After attempting ' + number + ' times, we finally reconnected!');
        });

        socket.on('reconnect_attempt', function (number) {
            console.info('Reconnect attempt number ' + number);
        });

        socket.on('connect_error', function () {
            console.warn('Error connecting to Socket.IO');
        });

        socket.on('reconnect_failed', function () {
            console.error('We failed to reconnect to Socket.IO. We give up.');
        });

    </script>
</body>

1.我先运行服务端,再在浏览器访问上面代码的页面,页面显示正常 2.我关闭服务端控制台,客户端浏览器有连接报错,但是没有console的日志输出 chrome浏览器截图如下,谢谢: 微信截图_20210429161908.png

2 回复

把下面这行代码在浏览器控制台中执行,也没用: localStorage.debug = ‘*’;

监听 connect 事件试试。

回到顶部