Solved

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

Posted on 2006-11-30
3
9,753 Views
Last Modified: 2012-06-27
Hi,

When I try to connect to a machine (229.2.0.2 on port 9202) I get the java.net.BindException.

When I try connecting to localhost, I do not get the exception.  Also, I do not get an exception when I try connecting to a machine on my local network.

I would like to know why I cannot bind to this address, and I would like to know a workaround or solution.

Thanks!

Output of TestServer:

Host Address=229.2.0.1
Port        =9201
Exception in thread "main" java.net.BindException: Cannot assign requested address: Cannot bind
      at java.net.PlainDatagramSocketImpl.bind0(Native Method)
      at java.net.PlainDatagramSocketImpl.bind(PlainDatagramSocketImpl.java:82)
      at java.net.DatagramSocket.bind(DatagramSocket.java:368)
      at java.net.MulticastSocket.<init>(MulticastSocket.java:147)
      at TestServer.main(TestServer.java:17)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)

TestServer source code:

import java.net.*;

public class TestServer {

 public static void main(String[] args) throws Exception {

   if (args.length != 2) {
     System.out.println("Usage: java TestServer <host_address_ipv6> <port>");
     System.exit(1);
   }

   System.out.println("Host Address="+args[0]);
   System.out.println("Port        ="+args[1]);

   ServerSocket ss = new ServerSocket();
   InetSocketAddress isa = new InetSocketAddress(InetAddress.getByName(args[0]), Integer.parseInt(args[1]));
   new MulticastSocket(isa);

   System.out.println("ServerSocket Bound");

 //  ss.accept();
 }
}
0
Comment
Question by:Gezna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 18047358
the host should either be localhost, or any other host address of local computer - should never be remote host address
0
 
LVL 12

Expert Comment

by:enachemc
ID: 18048221
make sure that there is no other process that uses that port.
0
 

Accepted Solution

by:
geoff2k earned 500 total points
ID: 18048679
You can only bind to ip addresses that are bound to an adapter on your local machine.   Under Windows you can use "ipconfig /all" to get a list of all the addresses that are local to you:

c:>ipconfig /all | find "IP Address"
        IP Address. . . . . . . . . . . . : 192.168.47.1
        IP Address. . . . . . . . . . . . : 192.168.159.1
        IP Address. . . . . . . . . . . . : 10.0.0.14
        IP Address. . . . . . . . . . . . : 10.31.0.240

I can successfully bind to any of the above addresses as well as 127.0.0.1 (localhost).  Any other procudes the error you mention.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
runtime exception 2 50
How do I remove an object from a 3 53
pagenation logic how it is working in my code 1 71
running on tomcat not jboss eap 7.0 3 32
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question