In my application I have implemented real time with socket-io with an external server (https://api.xxxxx.com:300)
Currently it works perfectly for iOS, but Android never gets to connect to the server.
On the server, socket io is declared as follows
var app = require('express')();
var fs = require('fs');
var options = {...};
var https = require('https').Server(options, app);
var io = require('socket.io')(https);
var curl = require('http');
io.on('connection', function(socket){
....
});
https.listen(3000, function(){
console.log('listening on *:3000');
});
In my App.js File, I have to start the connection with the following code:
// Initialize Socket IO:
global.socket = socketIO("https://api.xxxxx.com:3000", {
transports: ['websocket'],
forceNew: true,
reconnectionDelay: 3000,
reconnection: true,
reconnectionAttempts: Infinity,
jsonp: false
});
socket.connect();
console.warn('First', JSON.stringify(socket['io']));
socket.on('connect', () => {
console.warn('Connect Correctly');
});
console.warn('Second', JSON.stringify(socket['io']));
As you can see, I print the state of the socket to see the readyStatus that at the moment First an Second always appears with readyStatus: "opening"
Later, I check the status of the socket in my application and a readyStatus: closed appears.
I remember that this only happens to me in Android, in iOS the operation is perfect and always ends with the connected state.
The versions that I have in my application are the following:
{
"name": "xxxxxx-app",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"@react-native-community/async-storage": "^1.6.2",
"expo": "^35.0.0",
"i18n-js": "^3.3.0",
"json-circular-stringify": "0.0.1",
"moment": "^2.24.0",
"native-base": "^2.13.5",
"react": "16.8.3",
"react-dom": "16.8.3",
"react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz",
"react-native-web": "^0.11.7",
"react-navigation": "^3.13.0",
"socket.io-client": "^2.1.1"
},
"devDependencies": {
"babel-preset-expo": "^7.0.0"
},
"private": true
}