Skip to content

Commit b9170db

Browse files
committed
ClientsData updated
1 parent 8c9a007 commit b9170db

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

src/client/ClientThread.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public synchronized void run() {
5050
} else {
5151
streamOut.writeObject(new Message( Message._NAME_, "Bonjour " + clientName + " et bienvenue dans le chat. Pour communiquer avec les utilisateurs, il est nécessaire de se positionner à leur portée", clientName, 0, 0, null));
5252
}
53+
ArrayList<Client> clients = getClients();
54+
55+
5356
//streamOut.flush();
5457
}
5558

@@ -86,10 +89,12 @@ public synchronized void run() {
8689
}
8790

8891
public synchronized void sendMessages(ArrayList<Message> messages){
92+
ArrayList<Client> clients = getClients();
8993

9094
for(ClientThread thread : threads){
9195
for(Message message : messages){
9296
try {
97+
message.clients = clients;
9398
/*MessageValidator val = new MessageValidator(this.clientData, thread.clientData);
9499
if(this == thread || val.isClientsNear() == true)
95100
thread.streamOut.writeObject(message);
@@ -108,7 +113,6 @@ public synchronized void sendMessage(Message message){
108113
messages.add(message);
109114
sendMessages(messages);
110115

111-
//TODO : Le message est sensé contenir la listes des clients lq cette méthode est appelée par refreshClientData
112116
System.out.println("ClientThread.sendMessage :" + messages);
113117
}
114118

@@ -117,14 +121,12 @@ public synchronized void refreshClientData(String name, int posX, int posY){
117121
this.clientData.setX(posX);
118122
this.clientData.setY(posY);
119123

120-
System.out.println("ClientThread.refreshClientData :"+this.clientData);
121124
System.out.println(name+" position has been updated");
122-
125+
}
126+
127+
public synchronized Message createClientsMessage(){
123128
ArrayList<Client> clients = getClients();
124-
125-
System.out.println("ClientThread.refreshClientData getClients() :"+ clients);
126-
127-
sendMessage(new Message(Message._CLIENTS_, "", "", 0, 0, clients));
129+
return (new Message(Message._CLIENTS_, clients));
128130
}
129131

130132
public ArrayList<Client> getClients(){

src/client/ReceivingThread.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ public void run()
3232
if(msg.type == Message._NAME_){
3333
this.client.setName(msg.clientName);
3434
}
35-
if(msg.type == Message._CLIENTS_){
36-
this.client.setClientsData(msg.clients);
37-
continue;
38-
}
35+
this.client.setClientsData(msg.clients);
3936
this.client.notifyObservers("<"+msg.clientName+">"+msg.text);
40-
System.out.println("ReceivingThread.run thisClients : "+this.client.getClientsData());
37+
System.out.println("ReceivingThread.run Message :" + msg);
4138
}
4239

4340
} catch (IOException | ClassNotFoundException e) {

src/model/Message.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class Message implements Serializable {
1515
public final static int _CLIENTS_ = 2;
1616
public final static int _DISCONNECT_ = 3;
1717
public final static int _POSITION_ = 4;
18+
public final static int _CONNECT_ = 5;
1819

1920
public int type;
2021
public String text;
@@ -33,6 +34,11 @@ public Message(int type, String text, String clientName, int posX, int posY, Arr
3334
this.posY = posY;
3435
this.clients = clients;
3536
}
37+
38+
public Message(int type, ArrayList<Client> clients){
39+
this.type = type;
40+
this.clients = clients;
41+
}
3642

3743
@Override
3844
public String toString() {

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