[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2006-11-30
3
Medium Priority
?
9,970 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 1500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

656 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