【发布时间】:2014-06-01 03:35:22
【问题描述】:
我有一个简单的逻辑 Java 来检查端口是否已在使用中:
public static boolean isPortInUse(int port)
{
ServerSocket socket = null;
try {
socket = new ServerSocket(port);
socket.setReuseAddress(true);
} catch (Exception e) {
return true;
}
finally
{
if (socket != null) {
try {
socket.close();
} catch (Exception e) {
return true;
}
}
}
return false;
}
我是套接字编程的新手,所以我无法理解"setReuseAddress"here 方法的用途。我已经查看了this link,但我并不清楚它的目的。
【问题讨论】: