Node.js Websocket Error "error: Listen Eaddrnotavail Error: Listen Eaddrnotavail"
Solution 1:
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 :22
or lsof -i :80
or lsof -i :8000
and kill PID
of the process.
How to change the listening PORT in total.js?
- in /app/config or /app/config-release or /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.js or 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
// 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
Solution 2:
Just saw this today. User had commented out 127.0.0.1 localhost
in their /etc/hosts
file, and another network service was resolving localhost
to a different IP address not associated with the user's machine.
Solution was to add this line to /etc/hosts
127.0.0.1 localhost
Solution 3:
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.
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.js
orserver.listen(3000); // any number > 1024
For production (never run node on production with root access.)
you have to map the listening port (ex:3000) to 80 using ip tables
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport80 -j REDIRECT --to-port3000
Solution 4:
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
I would recommend you to run node apps for development on ports 8000-9000, but you can use any from the registered ports range.
Solution 5:
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.
sysctl -a | grep net
should show all network connection settings.
sysctl -a | grep port
for port range settings.
sysctl -a | grep keep
for tcp wait settings.
See here and here(mac here) for a little more detail/advice on what the settings are.
If you are going to modify settings, I would suggest that you first copy /etc/sysctl.conf
to something like /etc/sysctl.conf.bak
and 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.
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/
Post a Comment for "Node.js Websocket Error "error: Listen Eaddrnotavail Error: Listen Eaddrnotavail""