You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the moment our code in clientHandler.handleConnections() isn't using threads or async I/O and can therefore not handle multiple clients at the same time. Can be seen as some sort of a bug and will have impacts on future developement.
I propose moving the call to serverSocket.accept() into our start method in Server class and then call ClientHandler handleConnection with the retrieved Socket objekt in a new thread.
Since we are using Java21 i propose using virtual threads.
Code suggestions:
public void start() {
try {
System.out.println("Server started on port 1883");
while (!serverSocket.isClosed()) {
Socket connection = null;
connection = serverSocket.accept();
Thread.ofVirtual(() -> clientHandler.handleConnection(connection));
}
} catch (Exception e) {
e.printStackTrace();
}
}
The text was updated successfully, but these errors were encountered:
Problem Description
At the moment our code in clientHandler.handleConnections() isn't using threads or async I/O and can therefore not handle multiple clients at the same time. Can be seen as some sort of a bug and will have impacts on future developement.
I propose moving the call to serverSocket.accept() into our start method in Server class and then call ClientHandler handleConnection with the retrieved Socket objekt in a new thread.
Since we are using Java21 i propose using virtual threads.
Code suggestions:
The text was updated successfully, but these errors were encountered: