Added missing stop Method for NetworkServer
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>dev.unlegitdqrk</groupId>
|
||||
<artifactId>unlegitlibrary</artifactId>
|
||||
<version>1.6.6</version>
|
||||
<version>1.6.7</version>
|
||||
<url>https://unlegitdqrk.dev/</url>
|
||||
<description>Just a big library</description>
|
||||
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user