Ion application will not connect to Socket.IO

I have a small node application configured for Socket.IO connections:

var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);

io.on('connection', function (socket) {
    console.log('socket connected');

    socket.on('disconnect', function () {
        console.log('socket disconnected');
    });

    socket.emit('text', 'wow. such event. very real time.');
});

server.listen(3000, function() {
    console.log('Socket.io Running');
});

In my Ionic app, I have the following:

$ionicPlatform.ready(function(device) {
    var socket = io('http://192.168.1.9:3000');

    if (window.cordova && window.cordova.plugins.Keyboard) {
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if (window.StatusBar) {
        StatusBar.styleDefault();
    }
    alert('here');
    $state.go('signin');
});

When the Ionic application starts, I get a warning, so I know that the event is platform.readytriggering. But the Ionic app never connects to a socket session on the server.

If I test the Ionic app using Chrome, I am logging the following errors:

Failed to load resource: the server responded with a status of 404 (Not Found) http://192.168.1.9:3000/socket.io/?EIO=3&transport=polling&t=1443883896073-0
Failed to load resource: the server responded with a status of 404 (Not Found) http://192.168.1.9:3000/socket.io/?EIO=3&transport=polling&t=1443883899867-1
Failed to load resource: the server responded with a status of 404 (Not Found) http://192.168.1.9:3000/socket.io/?EIO=3&transport=polling&t=1443883901481-2
Failed to load resource: the server responded with a status of 404 (Not Found) http://192.168.1.9:3000/socket.io/?EIO=3&transport=polling&t=1443883904606-3

But the IP address and port numbers are correct.

Why is Ionic not connecting to Socket.iO?

EDIT - 04/10/2015

My Ionic project uses the cordova-plugin-whitelist plugin and a security policy tag is added in my index.html <meta>.

EDIT 10/10/2015

I also tried uninstalling and re-adding the Android platform, but it still does not work.

+4

Source: https://habr.com/ru/post/1610096/


All Articles