0

I have a jboss server running, and inside webapplication there code below. The question is I can not connect to server. The interesting thing is if I write 127.0.0.1 instead of 0.0.0.0 all is ok.

I am running jboss server with this command:

#!/bin/sh
nohup sh run.sh -b 0.0.0.0 -c crm &

this is the sample code

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.URL;

public class Test{
        public static void main(String []args){
                System.out.println("TEST");
                System.setProperty("java.net.preferIPv4Stack" , "true");
                String url="http://0.0.0.0:8080/webapp/vacancies?rabota=rabota&area=7232&speciality=Стораж&email=&phone=77019813144";
                System.out.println("START");
                try{
                        URL yahoo = new URL(url);
                        BufferedReader in = new BufferedReader(new InputStreamReader(yahoo.openStream()));
                        String inputLine;
                        while ((inputLine = in.readLine()) != null) {
                                System.out.println(inputLine);
                        }
                        System.out.println("FINISH!");
                        in.close();
                    }
                    catch (Exception e)
                    {
                      System.out.println("ERROR opening jobs servlet: " + e.getLocalizedMessage());
                    }
        }
}

so in the end I am getting connection timeout exception.

samlabs821
  • 27
  • 6

2 Answers2

2

0.0.0.0 is not a valid IP. It's used to indicate unknown/invalid. On some apps, it's used to indicate "bind to all addresses on a particular interface". In your case, it's simply invalid.

Marc B
  • 356,200
  • 43
  • 426
  • 500
1

There is a complete thread on why 0.0.0.0 cannot work at Is 0.0.0.0 a valid IP address?;.

The difference between 0.0.0.0 and 127.0.0.1 is covered in details at https://serverfault.com/questions/78048/whats-the-difference-between-ip-address-0-0-0-0-and-127-0-0-1.

If you want your code to work, you must change http://0.0.0.0:8080 to http://127.0.0.1:8080 or use the system interface(the correct ip address).

Community
  • 1
  • 1
randominstanceOfLivingThing
  • 16,873
  • 13
  • 49
  • 72