Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception : java.net.BindException: Cannot assign requested address

Tags:

java

android

I want to send and receive datagram socket but I'm getting exception java.net.BindException: Cannot assign requested address. I passed the correct ipaddress of the server which I want to communicate and correct port no.

try {
    SocketAddress sockaddr = new InetSocketAddress("203.100.77.54", 8000);
    DatagramSocket sock = new DatagramSocket(sockaddr);
    DatagramPacket pack = new DatagramPacket(bData, bData.length);
    sock.send(pack);
} catch (FileNotFoundException fnfe) {
    Log.e(LOG_TAG, "FileNotFoundException");
} catch (SocketException se) {
    Log.e(LOG_TAG, "SocketException");
} catch (UnknownHostException uhe) {
    Log.e(LOG_TAG, "UnknownHostException");
} catch (IOException ie) {
    Log.e(LOG_TAG, "IOException");
}

Please help me.

like image 732
android Avatar asked Jan 26 '26 02:01

android


1 Answers

DatagramSockets aren't created with a target address. They are created with their own local bind-address, or none, which causes a default bind when first used. The target address is specified when constructing the DatagramPacket, or in the connect() method.

like image 122
user207421 Avatar answered Jan 27 '26 18:01

user207421



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!