Saturday, July 26, 2008

Java: Check server response

Java Version 1.4

try
{
   java.net.Socket s = new Socket();
   s.connect(new InetSocketAddress("192.168.0.157", 7777), 1000);
   s.close();
   System.out.println("Success");
}catch (Exception ex){
   System.out.println("Error : " + ex.getMessage());
   // failed
   // do redirect
}

Java Version 1.3

try{
   java.net.Socket s = new Socket(host, port);
   s.close();
}catch (Exception ex){
   // failed
   // do redirect
}

No comments:


Since 26 July 2008: