开发者

How can I know, what local port is used by Stream?

开发者 https://www.devze.com 2023-01-21 05:48 出处:网络
Is it possible to specify explicitly local port that sho开发者_运维技巧uld be used by net.Stream, or to find out what local port is used for connection?

Is it possible to specify explicitly local port that sho开发者_运维技巧uld be used by net.Stream, or to find out what local port is used for connection?

According to the documentation, local port cannot be specified:

stream.connect(port, host='127.0.0.1')


stream.connect(port, host='127.0.0.1')

listed the specified address with specified port.

If you want to open socket, you have to use net.createConnection(port, host='127.0.0.1'), http.createServer or smth like that... In Linux to show all listened sockets, type netstat -an


According to the node.js documentation (http://nodejs.org/api.html) there is no method or variable exposed that provides the information you are looking for. I would suggest either submitting a patch (http://nodejs.org/#contributing) or making a request through a mailing list (http://groups.google.com/group/nodejs).


If you control the server you could ask it to tell you. Not pretty, but not unlike the hoops you have to jump through when trying to negotiate peer-to-peer connections from behind NAT.

0

精彩评论

暂无评论...
验证码 换一张
取 消