【问题标题】:Android Nativescript won't connect to socket.io, IOS doesAndroid Nativescript 不会连接到 socket.io,IOS 会
【发布时间】:2017-08-05 18:09:26
【问题描述】:

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

我已经为 ios 开发了我的应用程序,并试图将其移植到 Android,但 socket.io 无法连接,我将问题从仅使用 socket.io 插件的模板缩小到一个简单的 hello world。 适用于 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's encrypt 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!!');
});

【问题讨论】:

    标签: websocket socket.io nativescript angular2-nativescript


    【解决方案1】:

    我有疑问,这似乎是真的,刚刚用一些知名供应商的付费证书替换了证书,现在一切运行顺利.. 显然 IOS 承认让我们加密,但 android 没有。至少socket io插件没有。因为图像通过 https 加载得很好,让我们加密。

    【讨论】:

      猜你喜欢
      • 2021-05-06
      • 2015-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多