Trying to remotely connect to a socket.io server via ports
I’m trying to make a multiplayer browser game to play with some friends remotely. I’m trying to set up the server (using socket.io and node.js) so they can join. I’ve been following various tutorials, and I set up port forwarding (as well as I could.) It works in the local network, but not remotely, and according to https://www.yougetsignal.com/tools/open-ports/ port 5000 is not open, which is the port I’m hosting the game on.
Here’s the code for my server:
// Dependencies var express = require('express'); var http = require('http'); var path = require('path'); var socketIO = require('socket.io'); var app = express(); var server = http.Server(app); var io = socketIO(server); app.set('port', 5000); app.use('/static', express.static(__dirname + '/static')); // Routing app.get('/', function(request, response) { response.sendFile(path.join(__dirname, 'index.html')); }); // Starts the server. server.listen(5000,'0.0.0.0', function() { console.log('Starting server on port 5000'); }); // Add the WebSocket handlers io.on('connection', function(socket) { }); var players = {}; io.on('connection', function(socket) { socket.on('new player', function() { players[socket.id] = { x: 300, y: 300 }; }); socket.on('movement', function(data) { var player = players[socket.id] || {}; if (data.left) { player.x -= 5; } if (data.up) { player.y -= 5; } if (data.right) { player.x += 5; } if (data.down) { player.y += 5; } }); }); setInterval(function() { io.sockets.emit('state', players); }, 1000 / 60);
I just want them to be able to join! I’m very new to networking-related stuff, but thanks in advance for any help 🙂