在我的服務器應用程序,我試圖處理它使用的ServerSocket類的服務器,關閉監聽的ServerSocket
- 啓動服務器,等待連接。
- 停止與客戶端連接的服務器。
- 停止正在等待客戶端的服務器。
我可以能夠啓動該服務器並使其等待客戶端線程中使用
socket = serverSocket.accept();
我想做什麼是我要手動關閉其正在等待連接的插座,我使用都試過了,
if (thread != null) {
thread.stop();
thread = null;
}
if (socket != null) {
try {
socket.close();
socket = null;
}
catch (IOException e) {
e.printStackTrace();
}
}
執行,即使插座變爲空,當我嘗試從客戶端連接到服務器上面的代碼後,連接被建立起來,所以我的問題是如何中斷的ServerSocket WHI ch在這裏監聽連接,
socket = serverSocket.accept();
沒有'SocketClosedException',只有'java.net.SocketException:socket closed' – 2015-09-24 11:28:32