import java.io.IOException;
import java.net.*;
/**
* Utility class to ping and server
**/
public class UtilityClass {
public static boolean pingServer(URI uri, int timeout) {
try(Socket socket = new Socket()) {
SocketAddress socketAddress = new InetSocketAddress(uri.getHost(), uri.getPort());
socket.connect(socketAddress, timeout);
return true;
} catch (IOException e) {
return false;
}
}
}
Ping a server using given URI using socket connection to check server availability.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.