Added missing stop Method for NetworkServer

This commit is contained in:
Finn
2025-12-11 10:32:05 +01:00
parent d95ff4c497
commit b267674b6f
2 changed files with 17 additions and 1 deletions

View File

@@ -95,6 +95,22 @@ public final class NetworkServer {
}
}
public boolean stop() {
for (ConnectionHandler connectionHandler : new ArrayList<>(connectionHandlers)) connectionHandler.disconnect();
incomingThread.interrupt();
try {
serverSocket.close();
serverSocket = null;
if (logger != null) logger.log("Server stopped");
else System.out.println("Server stopped");
return true;
} catch (Exception e) {
if (logger != null) logger.exception("Failed to stop", e);
else System.err.println("Failed to stop: " + e.getMessage());
return false;
}
}
private void incomingConnections() {
try {
while (!serverSocket.isClosed()) {