Can't connect to node.js server on my VPS

Ok, I hope this question is not stupid or repetitive. I promise I have researched and tested a lot.

I have a server on my VPS with this code:

var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);

server.listen(8080);

io.on('connection', function(socket) {
  socket.on('hello', function() {
    console.log('Hello received');
  }
}

      

And a client on a different machine:

<script>
  var socket = io.connect('http://[VPS Public IP]:8080');
  io.emit('hello');
</script>

      

This works when using private IP addresses and the same network. This does not work when using a public IP. Any idea why this is happening?

Thank.

+3


source to share


1 answer


Ok, after some testing I fixed my problem.

I realized that the VPS's public IP ( XXX209 ) is different from the IP they give me to connect via SSH ( XXX221 ) using the Serial Console tool.



I used this second IP XXX221 when my real public IP is the first. Once I used XXX209 it connected without any problem.

Thanks for your comments and ideas.

0


source







All Articles