Ping a server
Posted by Xingjuan
Last Updated: July 02, 2012
import java.io.*;
import java.net.*;

     public class PseudoPing {
         public static void main(String args[]) {
             try {
             Socket t = new Socket(args[0], 7);
             DataInputStream dis = new DataInputStream(t.getInputStream());
             PrintStream ps = new PrintStream(t.getOutputStream());
             ps.println("Hello");
             String str = is.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();}
     }
}
Related Content
C++ Simple TCP Server
C++ Simple TCP Server
Samath | Jan 05, 2017