简体   繁体   中英

node.js server external access not working

I have set up a node.js server that is supposed to serve HTML files from a directory to clients. It should also log any connecting and disconnecting clients. Both work perfectly, but only locally. I have already forwarded traffic on port 3000 to my server and deactivated its firewall. What else can I do to enable external access?

var express = require('express');
var socket = require('socket.io');
//app setup
var app = express();
var server = app.listen(3000, ready);

function ready(){
    console.log('setup completed\nlistening on port 3000\n\n');
}

app.use(express.static('public'));

//socket setup
var io = socket(server);

io.on('connection', newConnection);

function newConnection(socket){
   //some code
}

i have already forwarded traffic on port 3000 to my server

Thats the wrong way round. Your server listens on port 3000, but webservers offer there service under Port 80, so you have to forward Port 80 to Port 3000.

and deactivated its firewall.

Bad idea. Just open one port (80 or 3000 depending on where you do port forwarding). And usually Routers on the way will also block certain ingoing connections, so check that too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM