Chris
Chris

Reputation: 1654

Running /socket.io/socket.io.js using a public IP

So, I'm trying to run my Node.js on my private server. Now the thing is, I've created a chat program, which works great and all when I run it on a local network.

Now, when I change the IP's to my public IP it won't load the /socket.io/socket.io.js file. It says net::ERR_CONNECTION_TIMED_OUT

The parts of the code where I'm connecting are:

Server.js:

var mongo = require('mongodb').MongoClient,
    client = require('socket.io').listen(8080).sockets;
    console.log('info - socket.io started');

mongo.connect('mongodb://127.0.0.1/chat', function(err, db) {
    if(err) throw err;

Index.html:

<script src="http://94.211.125.196:8080/socket.io/socket.io.js"></script>

<script>
// Try connection
try {
    var socket = io.connect('http://94.211.125.196:8080');
} catch(e) {
    // Set status to warn user
}
</script>

I do have the required ports port forwarded to my server (8080 & 27017)

Upvotes: 0

Views: 857

Answers (1)

Preston Van Loon
Preston Van Loon

Reputation: 1060

You're not hosting the socket.io.js file. You need to include the js file from somewhere else or host it by starting a httpServer in your node script. Try using the socket.io cdn:

<script src="https://cdn.socket.io/socket.io-1.3.5.js"></script>

Upvotes: 1

Related Questions