Android Nativescript不会连接到socket.io,IOS会

时间:2017-08-04 13:18:06

标签: websocket socket.io nativescript angular2-nativescript

我正在运行一个非常令人沮丧的错误,试图用socket.io连接android(nativescript)应用程序

我已经为ios开发了我的应用并尝试将其移植到Android但socket.io无法连接,我将问题缩小到只有socket.io插件的模板的简单hello世界。 适用于IOS ,但不适用于Android。我得到了无声的错误

运行这段代码:

    export class AppComponent 
{
    socket;
    constructor()
    {
            console.log('constructor!');    
            this.socket = SocketIO.connect('https://eaglecar.org');
            this.socket.on('connect', ()=>
            {
                console.log('Connect!');
            });

            this.socket.on('error', (error) => 
            {
                console.log('Error!');
                console.log(error);
            });      
    }
}

有关信息,它使用let的加密ssl证书连接到服务器。

IOS控制台输出

CONSOLE LOG file:///app/app.component.js:8:20: constructor!
CONSOLE LOG file:///app/tns_modules/@angular/core/./bundles/core.umd.js:3053:20: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
CONSOLE LOG file:///app/tns_modules/nativescript-socket.io/common.js:41:22: nativescript-socket.io on connect []
CONSOLE LOG file:///app/app.component.js:11:24: Connect!

但是使用Android

无论是Connect!还是Error!

,它都会无声地失败
JS: constructor!
JS: Angular is running in the development mode. Call enableProdMode() to enable the production mode.

起初我在考虑计时错误,所以我尝试将连接附加到UI回调,函数被调用但没有错误。

无法找到任何与adb logcat相关的内容,但这看起来很正常:

    08-04 15:10:24.377 11162 11162 V JS      : constructor!
08-04 15:10:24.386 11162 11193 D NetworkSecurityConfig: No Network Security Config specified, using platform default
08-04 15:10:24.389 11162 11195 I System.out: (HTTPLog)-Static: isSBSettingEnabled false
08-04 15:10:24.389 11162 11195 I System.out: (HTTPLog)-Static: isSBSettingEnabled false

只是尝试将连接域更改为不存在且控制台中仍然没有错误的内容...

附加测试:

我做了2次测试:

  • 我在同一个应用程序中成功加载了https上的图像 具有相同证书的服务器
  • 我已成功连接到非安全的socket.io服务器 Android上的另一个端口(3000)。

服务器端

var fs = require('fs');
var options = {
    key:    fs.readFileSync('../ssl/keys/[this_is_a_valid_key].key'),
    cert:   fs.readFileSync('../ssl/certs/[this_is_a_valid_cert].crt')
};


var server = require('https').createServer(options);
server.listen(443,'eaglecar.org');
var io = require('socket.io').listen(server);


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

1 个答案:

答案 0 :(得分:1)

我怀疑并且它似乎是真的,只是用一个知名供应商的付费证书替换证书,现在一切运行顺利。显然IOS认识到让我们加密,但是android并没有。至少socket io插件没有。因为图像加载得很好,而且加密了。