Showing posts with label tcp server status. Show all posts
Showing posts with label tcp server status. Show all posts

Thursday, September 27, 2012

Checking Status Of Remote Server

This function will help you identify the status of a remote server


public static boolean check(String ip,int port){
        boolean flag=false;
        try {
            Socket soc= new Socket();
            SocketAddress socketAddress = new InetSocketAddress(ip, port);
           
           
            soc.connect(socketAddress, 5000); // 5 second timeout
            flag=true;
        } catch (Exception e) {
            // TODO: handle exception
            flag=false;
        }
        return flag;
    }