开发者

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

how to block the accept method of socket when server is waiting for the connection from client? my code is here:

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 = serv开发者_StackOverflow中文版erSocket.accept();
    // Thread input = new InputThread(clientSocket.getInputStream());
} catch (IOException e) {
    System.err.println("Accept failed.");
    System.exit(1);
}

I want to block the accept method which is waiting for the client..


serverSocket.accept() itself is blocking and blocks until a connection is made.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜