gpt4 book ai didi

javascript - 如何使用nodejs监听多个ips?

转载 作者:数据小太阳 更新时间:2023-10-29 05:55:15 25 4
gpt4 key购买 nike

var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(80, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

那么,如果我想收听 192.168.1.100,就这样吗?

var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(80, '127.0.0.1').listen(80,'192.168.1.100');

最佳答案

试试这个

var http = require('http');
function handler(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
};
http.createServer(handler).listen(80, '127.0.0.1');
http.createServer(handler).listen(80, '192.168.1.100');
// or listen to both instead - thx @FlashThunder
// http.createServer(handler).listen(80);

关于javascript - 如何使用nodejs监听多个ips?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18033178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com