繁体   English   中英

服务器在等待客户端连接时,如何阻止套接字的接受方法?

[英]how to block the accept method of socket when server is waiting for the connection from client?

服务器在等待客户端连接时,如何阻止套接字的接受方法? 我的代码在这里:

ServerSocket serverSocket = null;

try {
    serverSocket = new ServerSocket(4444, 100);
} catch (IOException e) {
    System.err.println("Could not listen on port: 4444.");
    System.exit(1);
}

Socket clientSocket = null;
try {
    clientSocket = serverSocket.accept();
    // Thread input = new InputThread(clientSocket.getInputStream());
} catch (IOException e) {
    System.err.println("Accept failed.");
    System.exit(1);
}

我想阻止正在等待客户端的accept方法。

serverSocket.accept()本身正在阻塞,直到建立连接为止。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM