Cordova App Socket.IO连接不工作 [英] Cordova App Socket.IO connection not working

查看:1252
本文介绍了Cordova App Socket.IO连接不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图设置我的cordova应用程序使用socket.io websocket连接,但我不能得到它连接时,我在调试模式下运行。我读过的一切告诉我这应该能工作,我做错了什么?

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?

服务器端

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

应用程式

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:


无法加载资源:net :: ERR_CONNECTION_REFUSED

Failed to load resource: net::ERR_CONNECTION_REFUSED

文件:xhr_proxy,行号:0,列:0

File: xhr_proxy, Line: 0, Column: 0


推荐答案

问题是我在浏览器中使用Ripple Emulator。它有一些crappy设置,限制域访问。你可以改变它,但我认为螺丝,并决定使用Android模拟器调试,而且工作正常。

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.

这篇关于Cordova App Socket.IO连接不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆