开发者

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

开发者 https://www.devze.com 2023-04-06 11:54 出处:网络
how to block the accept method of socket when server is waiting for the connection from client? my code is here:

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

精彩评论

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

关注公众号