1

I have two applications hosted in openshift v2, both have the same code, the first uses Node.js 0.10 and socket.io works perfectly. The second application uses Node.js 8.2.1 but socket.io doesn't work and I get the same error as in these other sites:

Client side receive polling on socket.io

Socket.io cannot connect, resorts to “polling”

Socket.io connection reverts to polling, never fires the 'connection' handler

I tried to make the answers, but without result, if the code is the same in my two applications.. What can be failing? It's necessary to make some changes in the new version of Node.js?

This is the relevant code in my application and information about it:

Both app run perfectly on ports 8080 or 3000.

SERVER

App.js

var fs = require('fs');
var express = require('express');
var app = express();
var server = require('http').Server(app);
var bodyParser = require ('body-parser');
var jwt = require('jsonwebtoken'); 
var io = require('socket.io')(server);

var server_ip_address = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1';
var server_port = process.env.OPENSHIFT_NODEJS_PORT || 3000;

server.listen(server_port, server_ip_address, function () {
      console.log( "APP Listening on: " + server_ip_address + ":" + server_port )
    }); 

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));

app.use(express.static(__dirname + '/')); 

app.get('/', function (req, res) {
  res.sendFile(__dirname + '/index.html');
});


io.on('connection', function (socket) { 

    console.log('USUARIO CONECTADO');

    socket.on('coordenada', function (data) {

        io.emit('notificacion', {
            Latitud: data.latitudData,
            Longitud: data.longitudData,
            Nombre: data.name
        });
    }); 
});

CLIENT

Controllers.js

app.controller('mapCtrl', function ($scope, NgMap, socket) {

vm = this;

socket.on('notificacion', function(data) {

    console.log("coordenada recibida: ", data.Latitud +","+ data.Longitud +" de "+ data.Nombre);

    var name = data.Nombre;

    vm.transportistas = [
        {id:'1', nombre: data.Nombre, posicion:[data.Latitud, data.Longitud]}
      ];

    NgMap.getMap().then(function(map) {
        vm.map = map;
        google.maps.event.trigger(vm.map, 'resize');
    });

});

vm.wayPoints = [
     {location: {lat:39.502223, lng: -0.363244}},
   ];

NgMap.getMap()
    .then(function(map) {

        vm.map = map;

        vm.map.setZoom(6);
        vm.map.setCenter(new google.maps.LatLng(40, -4));

  });

vm.mostrarDetalles = function(e, transportista) {
    vm.transportista = transportista;
    vm.map.showInfoWindow('foo-iw', transportista.id);
  };

});

factorias.js

app.factory('socket', ['$rootScope', function($rootScope) {
  var socket = io.connect();

  return {
    on: function(eventName, callback){
      socket.on(eventName, callback);
    },
    emit: function(eventName, data) {
      socket.emit(eventName, data);
    }
  };
}]);

And I get this on web console ONLY in the app with Node.js 8.2.1:

GET http://localhost/socket.io/?EIO=3&transport=polling&t=1448850081140-15
GET http://localhost/socket.io/?EIO=3&transport=polling&t=1448850080247-12
GET http://localhost/socket.io/?EIO=3&transport=polling&t=1448850080252-13
etc...

**I'm sorry for my English.

ElíasMarNev
  • 124
  • 1
  • 14
  • You need matching versions of socket.io on client and server. Mismatched versions will not work together. So, that's the first thing to check. You don't show what version of socket.io you are using on the server and you don't show how you get the client version of socket.io so we have no idea on either. – jfriend00 Aug 14 '17 at 00:50
  • Yes, this was the problem, I was using socket.io 1.* and now, with socket.io/2.0.3 work perfect, but only on local... when Im try to use on openshift 2, dont work.. I have tried use var socket = io.connect('http://tfg-eliasmarnev.rhcloud.com:3000/', {'forceNew':true }); instead of var socket = io.connect(); @jfriend00 – ElíasMarNev Aug 14 '17 at 10:39
  • Now I have this problem on openshift (on local work): net::ERR_CONNECTION_TIMED_OUT – ElíasMarNev Aug 14 '17 at 12:35

0 Answers0