从Node.js发出网络请求时如何指定网络接口? [英] How to specify a network interface when making net requests from Node.js?

查看:461
本文介绍了从Node.js发出网络请求时如何指定网络接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http.requestnet.connect中,是否可以指定一个网络接口来启动连接?

In either http.request or net.connect, is there an option that I can specify a network interface to initiate a connection?

OS级别的AFAIK我可以指定地址级别,或将负载平衡到路由表中.但是我软件中界面选择的方式不止于此,我想知道我是否可以在代码中做到这一点.

AFAIK in OS level I can specify address level, or load balancing into routing tables. But the way of interface choosing in my software is more than that, I wanna know if I can do that in codes.

推荐答案

节点内置了以下内容:

http://nodejs.org/api/net.html#net_net_connect_options_connectionlistener

http://nodejs.org/api/http.html#http_http_request_options_callback

请参见localAddress,只需将其设置为您要使用的接口的IP.

See localAddress, just set that to the IP of the interface you'd like to use.

这篇关于从Node.js发出网络请求时如何指定网络接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆