无法连接到Socket.io错误:xhr轮询错误

时间:2017-07-10 12:12:17

标签: node.js socket.io laravel-5.3 homestead

我正在使用带有laravel应用程序的Homestead。

我无法让客户端从服务器接收数据......

我的socket.js:

var server = require('http').Server();

var io = require('socket.io')(server);

var Redis = require('ioredis');
var redis = new Redis();


redis.subscribe('test-channel');

redis.on('message', function (channel, message) {
    message = JSON.parse(message);

    io.emit(channel + ':' + message.event, message.data);
});


/*Booting Up the Server : port 3000 */
server.listen(3000 , function(){
    console.log('The Server Is Running');
});

这是正在侦听正在运行的端口3000。 控制台输出:

vagrant@homestead:~/code/chatting-app$ nodemon -L socket.js 
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node socket.js`
The Server Is Running

在客户端,我也在听3000端口。

我使用一段代码来显示错误:

function checkSocketIoConnect(url, timeout) {
        return new Promise(function(resolve, reject) {
            var errAlready = false;
            timeout = timeout || 5000;
            var socket = io(url, {reconnection: false, timeout: timeout});

            // success
            socket.on("connect", function() {
                clearTimeout(timer);
                resolve();
                socket.close();
            });

            // set our own timeout in case the socket ends some other way than what we are listening for
            var timer = setTimeout(function() {
                timer = null;
                error("local timeout");
            }, timeout);

            // common error handler
            function error(data) {
                if (timer) {
                    clearTimeout(timer);
                    timer = null;
                }
                if (!errAlready) {
                    errAlready = true;
                    reject(data);
                    socket.disconnect();
                }
            }

            // errors
            socket.on("connect_error", error);
            socket.on("connect_timeout", error);
            socket.on("error", error);
            socket.on("disconnect", error);
        });
    }

    checkSocketIoConnect("http://192.168.10.10:3000").then(function() {
        console.log('succes');
    }, function(reason) {
        console.log(reason);
    });

但是这会显示以下错误:

Error: xhr poll error
Stacktrace:
[14]</n.prototype.onError@https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.7/socket.io.min.js:1:24221
[17]</</o.prototype.doPoll/<@https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.7/socket.io.min.js:1:29697
[9]</n.prototype.emit@https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.7/socket.io.min.js:1:13388
[17]</</i.prototype.onError@https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.7/socket.io.min.js:1:31004

我不知道该怎么办?!我尝试了我能想到的一切。

我的家园.Yaml档案:

enter image description here

感谢任何帮助...

1 个答案:

答案 0 :(得分:1)

它是ADBLOCKER

此页面已禁用广告拦截器,现在可以正常使用。

笨.........