我使用Connect编写了一个小的node.js应用程序,该应用程序提供一个网页,然后将其定期发送给它.它还接受用户的观察并将其记录到磁盘文件中.
I've written a small node.js app, using Connect, that serves up a web page, then sends it regular updates. It also accepts and logs user observations to a disk file.
只要我在本地主机上,它就可以正常工作,但是我无法在同一Intranet上让其他计算机看到它.我正在使用端口3000,但是更改为端口8080或80并没有帮助.
It works fine as long as I am on localhost, but I can't get other commputers on the same intranet to see it. I am using port 3000, but changing to port 8080 or 80 didn't help.
这是我用来建立连接的代码:
Here is the code I am using to set up the connection:
var io = require('socket.io'), connect = require('connect'); var app = connect().use(connect.static('public')).listen(3000); var chat_room = io.listen(app);如上所述,我尝试将端口号更改为8080或80,但没有发现任何区别,因此我不认为这是防火墙问题(但我可能错了).在阅读了有关HTTP的类似问题之后,我还考虑过将0.0.0.0添加到listen(),但似乎listen()并不需要IP掩码参数.
As stated above, I've tried changing the port number to 8080 or to 80, and didn't see any difference, so I don't think that it is a firewall problem (but I could be wrong). I've also thought about, after reading similar questions dealing with HTTP, to add 0.0.0.0 to the listen() but it doesn't seem that listen() takes an IP mask parameter.
推荐答案您的服务器套接字很可能绑定到回送IP地址127.0.0.1而不是所有IP地址"符号IP 0.0.0.0(请注意,这不是网络掩码).要确认这一点,请运行sudo netstat -ntlp(如果在Linux上)或netstat -an -f inet -p tcp | grep LISTEN(OSX),然后检查您的进程绑定到哪个IP(查找带有:3000"的行).如果看到"127.0.0.1",那就是问题所在.通过将"0.0.0.0"传递给listen调用来对其进行修复:
Most probably your server socket is bound to the loopback IP address 127.0.0.1 instead of the "all IP addresses" symbolic IP 0.0.0.0 (note this is NOT a netmask). To confirm this, run sudo netstat -ntlp (If you are on linux) or netstat -an -f inet -p tcp | grep LISTEN (OSX) and check which IP your process is bound to (look for the line with ":3000"). If you see "127.0.0.1", that's the problem. Fix it by passing "0.0.0.0" to the listen call:
var app = connect().use(connect.static('public')).listen(3000, "0.0.0.0");更多推荐
Node.js连接仅适用于本地主机
发布评论