I tried to check whether a port is free in a remote machine by trying to create a ServerSocket with port and IP address of the machine. IP is accessible from my machine. but it produces an Exception "Cannot assign requested address: JVM_Bind". I have seen many questions posted for this exception but does not answer for other than localhost.
my code is
try {
sock = hostName == null ? new ServerSocket(port) : new ServerSocket(port, 0, InetAddress.getByName(hostName));
return true;
} catch (Exception var14) {
flag= false;
} finally {
if (sock != null) {
try {
sock.close();
} catch (Exception e) {
e.printStackTrace();
}
}
hostname - IP adress, port - port number