栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Node.js

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Node.js

这是我的努力:

支持从命令行提供“从”和“到”,并支持远程计算机。

var net = require('net');// parse "80" and "localhost:80" or even "42mEANINg-life.com:80"var addrRegex = /^(([a-zA-Z-.0-9]+):)?(d+)$/;var addr = {    from: addrRegex.exec(process.argv[2]),    to: addrRegex.exec(process.argv[3])};if (!addr.from || !addr.to) {    console.log('Usage: <from> <to>');    return;}net.createServer(function(from) {    var to = net.createConnection({        host: addr.to[2],        port: addr.to[3]    });    from.pipe(to);    to.pipe(from);}).listen(addr.from[3], addr.from[2]);

(另存为proxy.js)

从localhost:9001转发=> localhost:80

$ node proxy.js 9001 80

或localhost:9001 => otherhost:80

$ node proxy.js 9001 otherhost:80

(这是基于安德烈的回答,谢谢!)



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/372902.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号