for (int i = 0; i < clients.length; i++) {
System.out.println("New Client Connected: "
+ clients[i].getRemoteDetail());
try {
clients[i].sendPacket(new NetworkMessage("Hello World"));
}
catch (IOException ex) {
ex.printStackTrace();
}
}
}
// handle disconnected clients
clients = server.getDisconnectedClients(); // all disconnected clients
if (clients.length > 0) {
System.out.println("DISCONNECTED CLIENT = " + clients.length);
}
for (int i = 0; i < clients.length; i++) {
System.out.println("Client Disconnected: "
+ clients[i].getRemoteDetail());
}
// handle new packets
clients = server.getReceivedPacketClients(); // all clients which
// received packets
for (int i = 0; i < clients.length; i++) {
NetworkPacket[] packets = clients[i].getReceivedPackets(); // get
// the
// packets
for (int j = 0; j < packets.length; j++) {
NetworkMessage packet = (NetworkMessage) packets[j];
System.out.println(clients[i].getRemoteDetail() + ": "
+ packet.getMessage());
try {
clients[i].sendPacket(new NetworkMessage("Server said OK"));
}
catch (IOException ex) {
ex.printStackTrace();
}