BAEL-3505: Added util class to check server connection (#9013)

* BAEL-3505: Added util class to check server connection

* fixed formatting

* removed unnecessary sout
This commit is contained in:
Maciej Główka 2020-04-16 21:23:23 +02:00 committed by GitHub
parent 23099cff16
commit 1239da8e6d
1 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,24 @@
package com.baeldung.connectexception;
import java.net.ConnectException;
import java.net.Socket;
public class ConnectionChecker {
public static void main(String[] args) {
String host = "localhost";
int port = 5000;
try {
Socket clientSocket = new Socket(host, port);
// successfully connected to host, do something with opened socket
clientSocket.close();
} catch (ConnectException e) {
// host and port combination not valid
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}