Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Nov 2004

    java.net.BindException: The address is not available

    I must admit I'm very confused. This is not a new state, just an irritating one.

    Anyway, I'm trying to open a ServerSocket on a 9500 using the Personal Profile (no generic connection framework stuff) and in one application (an HTTP Server) I open the socket this way

    ServerSocket serverSocket = new ServerSocket(new Integer(System
    .getProperty("utils.Httpd.port", "84")).intValue());
    try {
    while (true) {
    Socket socket = serverSocket.accept();
    System.out.println("Connection Made from " + socket);
    Httpd httpd = new Httpd(socket);
    Thread th = new Thread(httpd);

    } // end while true
    } catch (Exception e) {
    This works great! No problem. I close that application, go to a 2nd app and open the server socket this way.

    int serverSocketPort = 1313;
    try {
    JoinableServicesCache.serverSocket = new ServerSocket(
    } catch (IOException e) {
    System.out.println("Error - unable to execute "
    + e.toString());
    try {
    System.out.println("Addresss:" + InetAddress.getLocalHost());
    } catch (UnknownHostException e1) {
    System.out.println("Error - UnknownHostException "
    + e1.toString());


    This call to open a server socket results in an exception and the output

    Error - JMatos unable to execute java.net.BindException: The address is not available

    I then tried an example out of Elliotte Rusty Harold's "Java Network Programming" and gave more args to the open socket call but to no avail. That call was

    ServerSocket httpd = new ServerSocket(1313,10,InetAddress.getByName("");

    This resulted in the same thing. (I know the address because I can ping it).

    The only difference that I can see is that one is a local variable and other is a static but I don't think that should make and difference.

    Anyone have any ideas of what to try?



  2. #2
    Nokia Developer Expert
    Join Date
    Jun 2005

    Re: java.net.BindException: The address is not available

    It looks clear to me that the problem is that the port 1313 is being used by another system service.


  3. #3
    Registered User
    Join Date
    Nov 2004

    Re: java.net.BindException: The address is not available

    Yes, good thought. That's what I thought too so I wrote (following an example) a piece of code that listed the 'in use' ports. The result was

    ======== J9 2.2 Standard Output (Fri Jan 20 09:41:24 2006) ========
    There is server on port 4160.
    There is server on port 5001.
    There is server on port 5003.
    Finish List Servers 1 to 10000

    both 84 and 1313 were not being used.

    I think it has something to do with the way the ServerSocket binds to addresses. The only book I have on it is the O'Reilly "Java Network Programming" and in there it says that both the ServerSocket(int ort) and ServerSocket(int port,int queueLength) constructors "... bind to all local addresses by default". I am guessing that the 9500 has 2 addresses, the address as served by the DHCP server and the localhost/ address. It appears (to me) that when trying to bind to the address it was raising the exception. To test that out I tried to use the 3rd constructor ServerSocket(int port, int queueLength, InetAddress bindAddress) in a call that looked like

    ServerSocket httpd = new ServerSocket(1313,10,InetAddress.getByName(""));//From the book

    but got the same exception. I also changed the port number but again to no avail.

    I will continue trying stuff but any suggestions are very welcome!


    The code I used to check the server ports in use is as follows.

    public class ListServerPorts {

    private static final int FINISH_PORT = 10000;

    * @param args
    public static void main(String[] args) {
    ServerSocket server = null;
    for (int port = 1; port <= FINISH_PORT; port++) {
    try {
    server = new ServerSocket(port);
    } catch (IOException ex) {
    System.out.println("There is server on port " + port + ".");
    } finally {
    if (server != null) {
    try {
    } catch (IOException ignore) {
    } else
    server = null;
    }// end for
    System.out.println("Finish List Servers 1 to " + FINISH_PORT);

  4. #4
    Nokia Developer Expert
    Join Date
    Jun 2005

    Re: java.net.BindException: The address is not available

    Let me see if I understood it correctly: if you open a socket on port 84, it works, if you try it on port 1313, it does not, is that right? Actually, in your first post, in the second code snippet, you introduce 2 different things, potentially problematic: 1) a new port 2) JoinableServicesCache usage. Is there any possibility that the problem lies in this JoinableServicesCache class? Like trying to bind twice or so... just wondering.

    If you pass a null InetAddress, the system will bind your server socket to all available interfaces, so I don't think you should care about that.


Similar Threads

  1. Device WAP Address
    By Regan in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2005-11-21, 10:21
  2. PAP Error - Address not found 2003
    By rossaob in forum General Messaging
    Replies: 1
    Last Post: 2003-12-29, 10:29
  3. Aphanumeric Address formats on MM1?
    By shtobias in forum General Messaging
    Replies: 0
    Last Post: 2003-09-09, 07:49
  4. Help! Help! My IP address is changing like crazy !!
    By jwynn_in_nh in forum Mobile Java General
    Replies: 0
    Last Post: 2003-07-22, 22:10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts