![](/img/trans.png)
[英]How can I bind an (outbound, of course) HttpUrlConnection to a specific local ip address, when I have multiple NIC on my client machine?
[英]Is there a way to bind a DatagramSocket to any port on a specific nic or if I specify the nic I have to specify the port?
這在Java中是不可能的嗎? DatagramSocket.bind方法必須采用NULL或IP:PORT。 您不能僅傳遞描述NIC的IP並自動選擇端口。 除非我錯過了一些東西,否則這種說法是沒有意義的。
使用默認的DatagramSocket
構造函數。 這將綁定到任何端口。 您不必使用bind方法。
只需將端口號指定為零,或者按照Mike Q的建議將其省略即可。在兩種情況下,系統都會為您分配一個端口。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.