1

I'm trying to set up my cordova app to use socket.io websocket connection but I can't get it to connect when I run in debug mode. Everything I've read tells me this should work, what am I doing wrong?

Server Side

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

server.listen(5022, function () {
    console.log('listening on *:5022');
});

io.sockets.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.');
});

App

document.addEventListener('deviceready',    
    function() {
        onDeviceReady.bind(this);
        console.log('Device is Ready')
        var socket = io.connect('http://MyDomain:5022');
        socket.on('connect', function () {
            socket.on('text', function (text) {
                console.log(text);
            });
        });
    },
false);

I get the Device is Ready message, but I get this message:

Failed to load resource: net::ERR_CONNECTION_REFUSED

File: xhr_proxy, Line: 0, Column: 0

Community
  • 1
  • 1
Jamie Barker
  • 8,145
  • 3
  • 29
  • 64

1 Answers1

1

The problem was that I was using the Ripple Emulator in the browser. It has some crappy settings that restrict domain access. You can change it but I thought screw it and decided to use the Android Emulator to debug instead and it worked fine.

Jamie Barker
  • 8,145
  • 3
  • 29
  • 64