Updated 'MdgaServer' class.
Updated the 'MdgaServer' class by adding the 'shutdown' message to it.
This commit is contained in:
@@ -296,4 +296,21 @@ public void broadcast(ServerMessage message) {
|
|||||||
public void disconnectClient(int id) {
|
public void disconnectClient(int id) {
|
||||||
this.myServer.getConnection(id).close("");
|
this.myServer.getConnection(id).close("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will be used to shut down the server.
|
||||||
|
* It will iterate threw all connections of myServer attribute and check if they are equal to null. If not they will
|
||||||
|
* be closed. After that the myServer attribute will be closed and this program will be exited with the exit code 0.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void shutdown() {
|
||||||
|
for (HostedConnection client : this.myServer.getConnections()) {
|
||||||
|
if (client != null) {
|
||||||
|
client.close("Host closed the server.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.myServer.close();
|
||||||
|
this.exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user