Open TCP connection on a specific port
try (Socket socket = new Socket(InetAddress.getByName(hostname), port))
{
// do what you want with socket
}
catch(Exception e) {
LOGGER.debug("Socket TCP not opened",e);
} |
try (Socket socket = new Socket(InetAddress.getByName(hostname), port))
{
// do what you want with socket
}
catch(Exception e) {
LOGGER.debug("Socket TCP not opened",e);
}
Open UDP connection on a specific port
try (DatagramSocket datagramSocket = new DatagramSocket(port,InetAddress.getByName(hostname))){
// do what you want with datagramSocket
}
catch(Exception e) {
LOGGER.debug("Socket UDP not opened",e);
} |
try (DatagramSocket datagramSocket = new DatagramSocket(port,InetAddress.getByName(hostname))){
// do what you want with datagramSocket
}
catch(Exception e) {
LOGGER.debug("Socket UDP not opened",e);
}
Ping
InetAddress.getByName(address).isReachable(timeoutInMilliSeconds); |
InetAddress.getByName(address).isReachable(timeoutInMilliSeconds);