-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatClient.java
More file actions
73 lines (68 loc) · 1.55 KB
/
ChatClient.java
File metadata and controls
73 lines (68 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.net.UnknownHostException;
public class ChatClient {
/**
* classe per la gestione della chat di un progetto,
* contiene i metodi necessari per il corretto utilizzo
* della classe Chat
*/
/**
* istanza della chat di progetto
*/
private Chat client;
/**
* nome del progetto associato alla chat
*/
private String name;
/**
* thread utilizzato per avviare la connessione udp
* multicast
*/
private Thread t;
/**
*
* @param _name nome del progetto
* @param _address indirizzo ip multicast del progetto
* @throws UnknownHostException
* @throws IllegalArgumentException
*/
public ChatClient(String _name, String _address) throws UnknownHostException, IllegalArgumentException {
this.name = _name;
this.client = new Chat(_address);
this.t = new Thread(this.client);
}
/**
*
* @return nome del progetto alla quale è associata la chat
*/
public String getName() {
return this.name;
}
/**
* metodo per avviare la connessione all'indirizzo ip multicast
*/
public void start() {
this.t.start();
}
/**
* invia il messaggio all'indirizzo ip multicast del client
* @param msg
*/
public void sendMessage(String msg) {
this.client.sendMex(msg);
}
/**
* legge i messaggi ricevuti dal client
* @return stringa contenente l'elenco dei messaggi ricevuti
*/
public String readChat() {
return this.client.read();
}
/**
* chiude la connessione udp e termina il thread
* @throws InterruptedException
*/
public void join() throws InterruptedException {
this.client.stop();
this.t.join();
}
}