Skip to content

Commit 68ea754

Browse files
committed
updates
1 parent fe704b7 commit 68ea754

File tree

6 files changed

+7
-28
lines changed

6 files changed

+7
-28
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.

src/Server/ClientDetails.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/Server/ClientHandlerThread.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ public void run() {
2828
// Read some initial data like name, etc
2929
this.name = input.readUTF().trim();
3030

31-
ClientDetails clientDetails = new ClientDetails(input, output, socket, name);
32-
33-
Server.addClient(clientDetails);
31+
Server.addClient(this);
3432
Server.ui.write("Connected" + " -> " + name + ", Active Clients : " + Server.getTotalActiveClients());
3533
Server.broadcastMessage("Connected" + " -> " + name + ", Active Clients -> " + Server.getTotalActiveClients());
3634

@@ -51,7 +49,7 @@ public void run() {
5149
}
5250

5351
// connection over - cleanup
54-
Server.removeClient(clientDetails);
52+
Server.removeClient(this);
5553
input.close();
5654
output.close();
5755
socket.close();

src/Server/Server.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ public class Server {
1919
public static UI ui;
2020

2121
// for multi-client maintain array for outputStream of each client
22-
private static final List<ClientDetails> allConnectedClients = new ArrayList<>();
22+
private static final List<ClientHandlerThread> allConnectedClients = new ArrayList<>();
2323
// these methods make changes in a shared variable, hence they should be synchronized
24-
synchronized public static void addClient(ClientDetails client) { allConnectedClients.add(client); }
25-
synchronized public static void removeClient(ClientDetails client) { allConnectedClients.remove(client); }
24+
synchronized public static void addClient(ClientHandlerThread client) { allConnectedClients.add(client); }
25+
synchronized public static void removeClient(ClientHandlerThread client) { allConnectedClients.remove(client); }
2626
synchronized public static void broadcastMessage (String msg) {
27-
for (ClientDetails client : allConnectedClients) {
27+
for (ClientHandlerThread client : allConnectedClients) {
2828
try {
29-
client.outputStream.writeUTF(msg);
29+
client.output.writeUTF(msg);
3030
} catch (IOException e) {
3131
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, e);
3232
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy