Results 1 to 2 of 2
  1. #1
    JavaEmpires is offline Member
    Join Date
    Dec 2007
    Posts
    19
    Rep Power
    0

    Default Java failed to reach to a PC in local LAN

    Hi all,
    I tried to execute the following code
    Java Code:
                try{
                
                NetworkInterface ni = NetworkInterface.getByName("eth0");
                System.out.println("\nGetting Host Name ....");
                InetAddress[] addr = InetAddress.getAllByName("192.168.6.252");
                for(int i=0;i<addr.length;i++){
                  System.out.println("\nHost Name = "+addr[i].getHostName());
                  System.out.println("\nIs Reachable??  = "+addr[i].isReachable(10));
                }
                
            }
            catch(Exception e){
                System.out.println("\nError :"+e);
                e.printStackTrace();
            }
    and the output I got was :
    Java Code:
    Getting Host Name ....
    
    Host Name = 192.168.6.252
    
    Is Reachable??   = false
    But when i PING to 192.168.6.252 it replies back i.e it is reachable from my computer.
    What could be the problem in above code?

    Thanx in advance.

  2. #2
    undertow's Avatar
    undertow is offline Member
    Join Date
    Jan 2008
    Location
    Colorado USA
    Posts
    12
    Rep Power
    0

    Default

    javadoc mentions "A typical implementation will use ICMP ECHO REQUESTs if the privilege can be obtained, otherwise it will try to establish a TCP connection on port 7 (Echo) of the destination host."

    maybe the JVM is unable to get permission to do an ICMP echo, so it tries a TCP connect on port 7. If you are using windows i would have a look at firewall settings. The ping program might have intrinsic privilege elevation for that kind of thing.

    or maybe the instantiation of the NetworkInterface(doesnt look like you are using it at all) object could be blocking the request.
    Last edited by undertow; 01-24-2008 at 07:32 PM.

Similar Threads

  1. Replies: 3
    Last Post: 05-22-2011, 04:16 PM
  2. Replies: 1
    Last Post: 08-13-2007, 04:46 AM
  3. Loading of JSP file failed
    By Heather in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 08-06-2007, 02:15 AM
  4. Replies: 3
    Last Post: 08-01-2007, 05:20 PM
  5. Compile failed, messages should have been provided
    By leonard in forum New To Java
    Replies: 2
    Last Post: 07-30-2007, 06:36 PM

Posting Permissions

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