while (true) {
ServerSocket myServerSocket = new ServerSocket(9999);
开发者_StackOverflow中文版Socket skt = myServerSocket.accept();
Handling obj = new Handling();
obj.handle(skt);
}
When i first try this it works fine and accepts the Socket but then when it loops back it says the address is in use. How do I fix this?
Don't create a new ServerSocket in the loop - you only need to accept in the loop:
ServerSocket myServerSocket = new ServerSocket(9999);
while (true) {
Socket skt = myServerSocket.accept();
Handling obj = new Handling();
obj.handle(skt);
}
精彩评论