How could others, on a local network, access my No

2019-01-16 10:10发布

I have a pretty straight-forward question. I made a web game with NodeJS, and I can successfully play it by myself with multiple browser windows open side-by-side; however, I'd like to know if it's possible for other local machines to be able to access and play the game with me too.

I naively tried using this url: my-ip-address:8000 and it won't work.

11条回答
甜甜的少女心
2楼-- · 2019-01-16 10:57

And Don't Forget To Change in Index.html Following Code :

 <script src="http://192.168.1.4:8000/socket.io/socket.io.js"></script>
 <script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>

 var socket = io.connect('http://192.168.1.4:8000');

Good luck!

查看更多
我命由我不由天
3楼-- · 2019-01-16 10:59

your node.js server is running on a port determined at the end of the script usually. Sometimes 3000. but can be anything. The correct way for others to access is as you say...

http://your.network.ip.address:port/ e.g. http://192.168.0.3:3000

check you have the correct port - and the ip address on the network - not internet ip.

Otherwise, maybe the ports are being blocked by your router. Try using 8080 or 80 to get around this - otherwise re-configure your router.

查看更多
狗以群分
4楼-- · 2019-01-16 10:59
var http = require('http');
http.createServer(function (req, res) {
}).listen(80, '127.0.0.1');
console.log('Server running at http://127.0.0.1:80/');
查看更多
放我归山
5楼-- · 2019-01-16 10:59

I had this problem. The solution was to allow node.js through the server's firewall.

查看更多
女痞
6楼-- · 2019-01-16 11:03

The port is probably blocked by your local firewall or router. Hard to tell without details.

But there is a simple solution for which you don't have to mess with firewall rules, run node as a privileded process to serve on port 80, etc...

Check out Localtunnel. Its a great Ruby script/service, which allows you to make any local port available on the internet within seconds. It's certainly not useful for a production setup, but to try out a game with colleagues, it should work just fine!

查看更多
登录 后发表回答