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:
parent
23099cff16
commit
1239da8e6d
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue