mirror of
https://github.com/Akomry/sae302_applicom.git
synced 2025-12-06 08:43:54 +00:00
feat(event): ContactWithEventTest3.java: test passé (2.6.3)
This commit is contained in:
parent
df7442f7a6
commit
8b3a0e5b21
4 changed files with 158 additions and 5 deletions
|
|
@ -110,6 +110,35 @@ public class ChatServer {
|
|||
//client.echoLoop();
|
||||
}
|
||||
|
||||
public ChatClientHandler findClient(Contact contact) {
|
||||
for (ChatClientHandler user: clientList) {
|
||||
if (user.user.equals(contact)) {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void sendEventToContact(Contact contact, Event event) {
|
||||
ChatClientHandler user = findClient(contact);
|
||||
if (!(user == null)) {
|
||||
try {
|
||||
user.send(event.toString());
|
||||
} catch (Exception e) {
|
||||
LOGGER.warning("!!Erreur de l'envoi d'Event à %s, fermeture de la connexion".formatted(user.user.getLogin()));
|
||||
user.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sendEventToAllContacts(Event event) {
|
||||
for (Contact contact: contactMap.values()) {
|
||||
if (contact.isConnected()) {
|
||||
sendEventToContact(contact, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ContactMap getContactMap() {
|
||||
return contactMap;
|
||||
}
|
||||
|
|
@ -133,6 +162,8 @@ public class ChatServer {
|
|||
*/
|
||||
private String ipPort;
|
||||
|
||||
private Contact user;
|
||||
|
||||
/**
|
||||
* Initialise les attributs {@link #sock} (socket connecté au client),
|
||||
* {@link #out} (flux de caractères UTF-8 en sortie) et
|
||||
|
|
@ -220,14 +251,10 @@ public class ChatServer {
|
|||
} else {
|
||||
LOGGER.info("Connexion de " + login);
|
||||
contactMap.getContact(login).setConnected(true);
|
||||
this.user = contactMap.getContact(login);
|
||||
}
|
||||
}
|
||||
|
||||
public ChatClientHandler findClient(Contact contact) {
|
||||
String login = contact.getLogin();
|
||||
Contact contactRes = contactMap.get()
|
||||
}
|
||||
|
||||
public void send(String message) throws IOException {
|
||||
LOGGER.finest("send: %s".formatted(message));
|
||||
out.println(message);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue