Javascript Node.js websocket 错误“错误:监听 EADDRNOTAVAIL 错误:监听 EADDRNOTAVAIL”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26276952/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Node.js websocket error "Error: listen EADDRNOTAVAIL Error: listen EADDRNOTAVAIL"
提问by hash
Application work fine on localhost .but when its connect to server it getting error.
I connect server through port 22
应用程序在 localhost 上工作正常。但是当它连接到服务器时出现错误。
我通过端口 22 连接服务器
This is the error
这是错误
Error: listen EADDRNOTAVAIL Error: listen EADDRNOTAVAIL
at errnoException (net.js:904:11)
at Server._listen2 (net.js:1023:19)
at listen (net.js:1064:10)
at net.js:1146:9
at dns.js:72:18
at process._tickCallback (node.js:419:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:906:3
Any Help !!!
任何帮助!!!
-update-
-更新-
i run netstat -tulpn | grep 22
我跑 netstat -tulpn | grep 22
Result:
结果:
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 683/sshd
tcp6 0 0 :::22 :::* LISTEN 683/sshd
but i run netstat -tulpn | grep 80
但我跑 netstat -tulpn | grep 80
Nothing Display.
无显示。
Any Help.is this server fault?
任何帮助。这是服务器故障吗?
running netstat -nlt
跑步 netstat -nlt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:5901 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:5902 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:6001 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:6002 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:631 :::* LISTEN
Running netstat -anp | grep :80
跑步 netstat -anp | grep :80
tcp 1 0 162.243.145.226:60728 91.189.94.25:80 CLOSE_WAIT 1726/ubuntu-geoip-p
tcp 1 0 162.243.145.226:47842 74.125.239.148:80 CLOSE_WAIT 8104/epiphany-brows
tcp 1 0 162.243.145.226:60727 91.189.94.25:80 CLOSE_WAIT 1417/ubuntu-geoip-p
tcp 1 0 162.243.145.226:58818 198.41.30.199:80 CLOSE_WAIT 8104/epiphany-brows
采纳答案by Peter Sirka
You are using a used port. You must change a port or you must kill a process which is listening on a port. Open terminal and write (example): lsof -i :22or lsof -i :80or lsof -i :8000and kill PIDof the process.
您正在使用已使用的端口。您必须更改端口或必须终止正在侦听端口的进程。打开终端并写入 (example): lsof -i :22or lsof -i :80or lsof -i :8000and kill PIDof the process。
How to change the listening PORTin total.js?
如何更改total.js 中的监听端口?
- in /app/configor /app/config-releaseor /app/config-debug:
- 在/app/config或/app/config-release或/app/config-debug 中:
default-ip : 127.0.0.1
default-port : 8000
or
或者
// For e.g. Heroku
default-ip : auto
default-port : auto
- if exist files: release.jsor debug.js:
- 如果存在文件:release.js或debug.js:
var fs = require("fs");
var options = {};
// options.ip = "127.0.0.1";
// options.port = parseInt(process.argv[2]);
options.port = 8000;
- if exists only index.js
- 如果只存在index.js
// for development:
require('total.js').http('debug', { port: 8000 });
// or for production:
require('total.js').http('release', { port: 8000 });
Thanks and documentation: http://docs.totaljs.com
感谢和文档:http: //docs.totaljs.com
回答by Cory Klein
Just saw this today. User had commented out 127.0.0.1 localhostin their /etc/hostsfile, and another network service was resolving localhostto a different IP address notassociated with the user's machine.
今天刚看到这个。用户必须注释掉127.0.0.1 localhost在他们的/etc/hosts文件,和其他网络服务被解析localhost到一个不同的IP地址不与用户的机器有关。
Solution was to add this line to /etc/hosts
解决方案是将此行添加到 /etc/hosts
127.0.0.1 localhost
回答by Mahmoud.Mahfouz
I think you are using a Unix based OS, if that is the case then you can't use any port below 1024 without sudo access.
我认为您使用的是基于 Unix 的操作系统,如果是这种情况,那么您不能在没有 sudo 访问权限的情况下使用 1024 以下的任何端口。
Also before digging too deep check that the listening port is not being used by any other process.
此外,在深入挖掘之前,请检查侦听端口是否未被任何其他进程使用。
A quick fix (for development only):
快速修复(仅用于开发):
sudo node file.jsorserver.listen(3000); // any number > 1024
sudo node file.js或者server.listen(3000); // any number > 1024
For production (never run node on production with root access.)
对于生产(永远不要在具有 root 访问权限的生产上运行节点。)
you have to map the listening port (ex:3000) to 80 using ip tables
您必须使用 ip 表将侦听端口(例如:3000)映射到 80
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
回答by Michael
Port 22 is reserved for ssh and on the list of well known ports, please check http://en.wikipedia.org/wiki/Port_(computer_networking)#Common_port_numbers
端口 22 是为 ssh 保留的,在众所周知的端口列表中,请查看http://en.wikipedia.org/wiki/Port_(computer_networking)#Common_port_numbers
I would recommend you to run node apps for development on ports 8000-9000, but you can use any from the registered ports range.
我建议您在端口 8000-9000 上运行节点应用程序进行开发,但您可以使用已注册端口范围中的任何一个。
回答by Tyler Christian
If you are only reaching this error after many requests, you might want to check your port range settings and adjust them. There is also TCP timeout settings, such as FIN_WAIT that can keep connections open for longer than expected.
如果您在多次请求后才遇到此错误,您可能需要检查您的端口范围设置并进行调整。还有 TCP 超时设置,例如 FIN_WAIT 可以使连接保持打开的时间比预期的要长。
sysctl -a | grep netshould show all network connection settings.
sysctl -a | grep net应显示所有网络连接设置。
sysctl -a | grep portfor port range settings.
sysctl -a | grep port用于端口范围设置。
sysctl -a | grep keepfor tcp wait settings.
sysctl -a | grep keep用于 tcp 等待设置。
See hereand here(mac here) for a little more detail/advice on what the settings are.
有关设置内容的更多详细信息/建议,请参见此处和此处(此处为mac )。
If you are going to modify settings, I would suggest that you first copy /etc/sysctl.confto something like /etc/sysctl.conf.bakand then modify the setting in that file. They can be adjusted via the command-line but that is temporary and resetting them can be a mess.
如果您要修改设置,我建议您先复制/etc/sysctl.conf到类似文件中/etc/sysctl.conf.bak,然后再修改该文件中的设置。它们可以通过命令行进行调整,但这是暂时的,重置它们可能会很麻烦。
You probably don't want to do this in production.
您可能不想在生产中这样做。
Additional docs:
附加文档:
https://ma.ttias.be/linux-increase-ip_local_port_range-tcp-port-range/
https://ma.ttias.be/linux-increase-ip_local_port_range-tcp-port-range/

