nodejs:错误:EADDRNOTAVAIL,无法分配请求的地址 [英] nodejs: Error: EADDRNOTAVAIL, Cannot assign requested address
问题描述
我在172.16.1.218上运行以下node.js服务器:
I have the following node.js server running on 172.16.1.218:
var net=require('net');
var server = net.createServer(function (socket) {
socket.write("Echo server\r\n");
socket.pipe(socket);
});
server.listen(6001, "172.16.1.218");
我可以远程登录到它,它会按预期的方式回显.
I can telnet into it and it echos as expected.
我在172.16.1.224上运行以下node.js服务器:
I have the following node.js server running on 172.16.1.224:
var net = require('net');
var server = net.createServer(function (socket) {
// Every time someone connects, tell them hello and then close the connection.
socket.addListener("connect", function () {
sys.puts("Connection from " + socket.remoteAddress);
socket.end("Hello World\n");
});
});
// Fire up the server bound to port 7000 on localhost
server.listen(6001,"172.16.1.218");
但是当我尝试运行它时,出现以下错误:
But when I try to run it, I get the following error:
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: EADDRNOTAVAIL, Cannot assign requested address
at Server._doListen (net.js:1100:5)
at net.js:1071:14
at Object.lookup (dns.js:159:5)
at Server.listen (net.js:1065:20)
at Object.<anonymous> (/home/hynese/Desktop/test.js:16:8)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
at Array.<anonymous> (module.js:421:10)
我已经关闭了所有防火墙,等等.我对这个错误一无所知.希望有人能帮忙.
I've turned off all firewalls, etc. I can't make any sense of this error. Hoping someone can help.
在此先感谢
推荐答案
在 172.16.1.224
上,您无法在 172.16.1.218
上收听,因为这不是计算机的IP你在听.
On 172.16.1.224
you cannot listen on 172.16.1.218
because that's not the IP of the machine you're listening on.
如果您想在那台机器上收听,请使用:
If you want to listen on that machine, use:
server.listen(6001,"172.16.1.224");
这篇关于nodejs:错误:EADDRNOTAVAIL,无法分配请求的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!