-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSharer.java
More file actions
32 lines (25 loc) · 935 Bytes
/
Sharer.java
File metadata and controls
32 lines (25 loc) · 935 Bytes
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
import java.net.*;
import java.util.List;
public class Sharer {
private InetAddress MCAST_ADDRESS;
private DatagramSocket SOCKET;
private int CLIENTPORT;
public Sharer (String mcastip, int clientPort) throws SocketException, UnknownHostException {
this.CLIENTPORT = clientPort;
this.MCAST_ADDRESS = InetAddress.getByName(mcastip);
this.SOCKET = new DatagramSocket(0);
}
public void notify (List<String> attempts_list, String username) {
// Manda in multicast le notifiche
String msg = username;
for (String tipsWord : attempts_list) {
msg = msg + ("&"+tipsWord);
}
msg = msg + "&++++++++++";
try {
this.SOCKET.send(new DatagramPacket(msg.getBytes(), msg.length(), MCAST_ADDRESS, CLIENTPORT));
} catch (Exception e) {
e.printStackTrace();
}
}
}