在 Node.js 上使用 http.createServer() 方法时,无法使用“127.0.0.1”以外的任何其他地址(包含在 IPv4 class A 中)
While using http.createServer() method on Node.js, unable to use any other address (included in IPv4 class A) than '127.0.0.1'
在 Node.js 上使用 http.createServer() 方法时,我无法使用“127.0.0.1”以外的任何其他地址。我的理解是我应该能够使用 Class A IPv4 地址下的任何地址,但事实并非如此,因为我会抛出一个错误。
谁能帮我理解一下?
终端错误日志:
代码:
const http = require('http');
const hostname = '127.0.0.1';
const port = 1337;
http.createServer((request, response) => {
response.writeHead(200, { 'Content-Type': 'text/plain' });
response.end('Hello World\n');
}).listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
您只能使用分配给您的一个网络接口的地址。 127.0.0.0 未分配给您的任何网络接口(也不可能)。本地主机地址为 127.0.01 到 127.255.255.254; 127.0.0.0 和 127.255.255.255 是网络/广播地址(或者 this comment 超级用户说的)。
在 Node.js 上使用 http.createServer() 方法时,我无法使用“127.0.0.1”以外的任何其他地址。我的理解是我应该能够使用 Class A IPv4 地址下的任何地址,但事实并非如此,因为我会抛出一个错误。
谁能帮我理解一下?
终端错误日志:
代码:
const http = require('http');
const hostname = '127.0.0.1';
const port = 1337;
http.createServer((request, response) => {
response.writeHead(200, { 'Content-Type': 'text/plain' });
response.end('Hello World\n');
}).listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
您只能使用分配给您的一个网络接口的地址。 127.0.0.0 未分配给您的任何网络接口(也不可能)。本地主机地址为 127.0.01 到 127.255.255.254; 127.0.0.0 和 127.255.255.255 是网络/广播地址(或者 this comment 超级用户说的)。