简体   繁体   中英

How to make node.js server accessible by public ip-address

I've been trying to make an online multiplayer game using nodeJS and socket.io. I am able to access through localhost:3000 to test out my website, but then now I want my friends to access it too.

var express = require('express');
var app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server, {});
server.listen(3000);

How can I make it so that other people can access my website using my public IP address that I found on http://cmyip.com , for example [external-ip]:3000.

I tried using ngrok, but it's very slow and socket.io that emits data every 30 ms is exceeding ngrok limit. Also, I don't want to use any DNS or other plugins, I just want it to be simple.

I'm using Mac OS so my firewall is disabled by default.

Here is my port-forwarding page: (my Local IP is 192.168.1.50) Am I doing it right? I have tried port-forwarding with games, and it works fine so I don't think it's my router. 在此处输入图片说明

If you sure that you don't have problem with router then you can try to listen 0.0.0.0 this mean you will listen external and internal IP adresses.

server.listen(3000,"0.0.0.0");

Also you still need to check your Brandmauer or Firewall.

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