[英]How to get the source port being used by java.net.HttpURLConnection?
I am using the java.net.HttpURlConnection
or javax.net.ssl.HttpsURLConnection
objects for connecting to http/https servers. 我正在使用
java.net.HttpURlConnection
或javax.net.ssl.HttpsURLConnection
对象连接到http / https服务器。 My tests failed at some point because apparently all they had used up all the available ports on my local machine. 我的测试在某个时候失败了,因为显然所有测试都用完了本地计算机上的所有可用端口。 These are persistent http connections and therefore should be reused.
这些是持久的http连接,因此应该重用。
I am trying a few things to fix this. 我正在尝试一些方法来解决此问题。 But to check whether my fix works, I need to make sure that the same port on the source machine is getting used in subsequent instances of
HttpURlConnection
or HttpsURLConnection
. 但是要检查我的修复程序是否有效,我需要确保在后续的
HttpURlConnection
或HttpsURLConnection
实例中使用源计算机上的同一端口。 How can I get the source port being used by java.net.HttpURLConnection
? 如何获取
java.net.HttpURLConnection
使用的源端口?
I don't see any methods that allows same local port bind in HttpURlConnection or get local port number being used for binding. 我没有在HttpURlConnection中看到任何允许相同本地端口绑定的方法,也没有获得用于绑定的本地端口号。 There is some methods in Java's Socket class that allows you to bind same local port ( constructor method and bind() I think ) though... Check PlainConnectionSocketFactory in Apache httpclient 4.x than Socket if you want to go this way since those HttpClient has more handy methods.
Java的Socket类中有一些方法可以允许您绑定相同的本地端口(我认为是构造函数方法和bind())...如果您想使用这种方法,请检查Apache httpclient 4.x中的PlainConnectionSocketFactory而不是Socket,因为那些HttpClient有更多方便的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.