Vincent Duprez
Vincent Duprez

Reputation: 3892

Android Nativescript won't connect to socket.io, IOS does

I'm running in a very frustrating error, trying to connect an android (nativescript) app with socket.io

I've developed my app for ios and trying to port it to Android but socket.io won't connect, I narrowed the problem down to a simple hello world from the templates with only the socket.io plugin. It works with IOS but not with Android. I get silent errors

running this bit of code :

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

For information, this connects to a server with a let's encrypt ssl certificate.

IOS console output

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!

But with Android

it silently fails given neither Connect! nor Error!

JS: constructor!
JS: Angular is running in the development mode. Call enableProdMode() to enable the production mode.

At first I was thinking about a timing error, so I tried to attach the connect to a UI callback, the function gets called but with no errors.

Can't find anything interresting with adb logcat but this, seems normal :

    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

Just tried to change the connecting domain to something that does not exist and still no error in the console...

Additional tests :

2 tests I made :

Server side

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

Upvotes: 0

Views: 900

Answers (1)

Vincent Duprez
Vincent Duprez

Reputation: 3892

I had doubts and it appears to be true, Just replaced the certificate with a paid certificate from some well known vendor and now everything runs smoothly.. Apparently IOS recognises let's encrypt but android doesn't. At least the socket io plugin doesn't. because images are loaded just fine over https with let's encrypt.

Upvotes: 1

Related Questions