Results 1 to 6 of 6

Thread: Ping program in java

  1. #1
    Join Date
    Dec 2009
    Posts
    202

    Ping program in java

    Hello,
    I have developed an ping program in java. But when I run the application then there is a "fatal exception" error message and the stack is:
    java.lang.ArrayIndexOutOfBoundsException: 0
    Exception in thread "main"
    My goal is to ping from my PC to an IP address. So how to continue the code to do this? Here's the code:
    Code:
    Public class simulate_ping
    {
     
    	Public static void hand(String args[]) 
    	{
    		try 
    		{
    			Socket t = new Socket(args[0], 7);
    DataInputStream dtinp = new DataInputStream(t.getInputStream());
    PrintStream prst = new PrintStream(t.getOutputStream());
    prst.System.out.println("Hello");
    String str = dtinp.readLine();
    			if (str.equals("Hello"))
    		        System.out.System.out.println("Alive!") ;
    		      else
    		        System.out.System.out.println("Dead or echo port not responding");
    t.close();
    		}
    		catch (IOException e) 
    		{
    			e.printStackTrace();
    		}
    	}
     
    }
    Last edited by ISAIAH; 21-01-2010 at 10:02 AM.

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Ping program in java

    Hello,
    For now with the class that you have you have to pass in the address you want, in the command line launching your class. Otherwise you can replace
    Code:
    Socket t = new Socket(args[0], 7);
    by this code
    Code:
    Socket t = new Socket("192.168.0.25", 7);
    Try using the second one then check the program if it works without any errors.

  3. #3
    Join Date
    Dec 2009
    Posts
    202

    Re: Ping program in java

    Hello,
    After substituting "192.168.x.x" Here are the error stack:
    java.net.ConnectException: Connection refused: connect
    java.net.PlainSocketImpl.doConnect at (Unknown Source)
    java.net.PlainSocketImpl.connectToAddress at (Unknown Source)
    java.net.PlainSocketImpl.connect at (Unknown Source)
    at java.net.Socket.connect (Unknown Source)
    What exactly this error means. Can you explain about this error in details please.
    Last edited by ISAIAH; 21-01-2010 at 10:01 AM.

  4. #4
    Join Date
    Dec 2009
    Posts
    296

    Re: Ping program in java

    Hello,
    Even I have an similar problem when I try to run my program which should give ping details. I run the program from the Eclipse software. In the browser of Eclipse there is a menu tree containing classpath. And when I check its contents by double clicking the icon in the classpath, I get
    Code:
    xml version ="1.0" encoding ="UTF-8"?>
    <classpath>
    <classpathentry kind ="src" path =""/>
    <classpathentry kind ="con" path ="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind ="output" path =""/>
    </ classpath>

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Ping program in java

    Hello,
    You do not need access to the source class PlainSocketImpl. Eclipse puts you to mail because it allows direct access to the endoirt where the error occurred. This error occurred in the course PlainSocketImpl class but your problem does not lie in this class. Looking more in detail your stack error. It comes from the line 11 to one of your programs. Also, when you read the error message is a connection problem. there are two possibilities: either the server does not answer (try a "real" table to see if it answers, if it does not, AC is useless to try to simulate a ping him). If it answers it in your code there is a problem.

  6. #6
    Join Date
    Dec 2009
    Posts
    202

    Re: Ping program in java

    Hello,
    Here is my updated program, can any one help me, I ma getting an error in line no. 12.
    Code:
    Public class simulate_ping
    {
     
    	Public static void hand(String args[]) 
    	{
    		try 
    		{
    			Integer port = new Integer("7");
    Socket t = new Socket("192.168.0.25", 7);
    DataInputStream dtinp = new DataInputStream(t.getInputStream());
    PrintStream prst = new PrintStream(t.getOutputStream());
    prst.System.out.println("Hello");
    String str = dtinp.readLine();
    			if (str.equals("Hello"))
    		        System.out.println("Alive!") ;
    		      else
    		        System.out.println("Dead or echo port not responding");
    t.close();
    		}
    		catch (IOException e) 
    		{
    			e.printStackTrace();
    		}
    	}
     
    }

Similar Threads

  1. Dr. Java program
    By bamggut29 in forum Software Development
    Replies: 2
    Last Post: 26-11-2011, 04:24 AM
  2. Need help to write this program in java?
    By frkadeel in forum Software Development
    Replies: 1
    Last Post: 01-12-2010, 03:58 PM
  3. Getting many Errors when trying to run the Java Program
    By N I C K in forum Software Development
    Replies: 5
    Last Post: 16-01-2010, 05:46 PM
  4. Calendar program in java
    By D_chapple in forum Software Development
    Replies: 3
    Last Post: 01-12-2009, 05:20 PM
  5. Link List Example in Java Sample program in Java
    By trickson in forum Software Development
    Replies: 2
    Last Post: 04-08-2009, 08:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,229,295.53624 seconds with 17 queries