jordygroote's avatar

Can't connect to Socket.io Error: xhr poll error

Hi i'm following @JeffreyWay's tutorial on socket.io with laravel: https://laracasts.com/series/real-time-laravel-with-socket-io/episodes/3?autoplay=true

I'm stuck.

I've done everything EXACTLY like him in this video's.

I'm using 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');
});

My welcome.blade to print error....

    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);
    });

</script>

Terminal vagrant ssh:

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

I don't know what to do. i tried everything

The error i get:

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

[17]</</i.prototype.create/e.onreadystatechange/<@https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.7/socket.io.min.js:1:30630

I;ve been stuck for 2 days!

Any help is appreciated

0 likes
1 reply

Please or to participate in this conversation.