Ping Server : Socket « Network « Android






Ping Server

    
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;

class Main {

  public static boolean pingGgServer(InetAddress addr, int port, int timeout) {
    Socket socket = new Socket();
    Exception exception = null;
    try {
      socket.connect(new InetSocketAddress(addr, port), timeout);
    } catch (IOException e) {
      exception = e;
    }

    finally {
      try {
        socket.close();
      } catch (IOException e) {
      }
    }

    return exception == null ? true : false;
  }
}

   
    
    
    
  








Related examples in the same category