blob: 24a040cd88de548f0444f89d0d700313c2031585 (
plain) (
blame)
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
|
package derms.net;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
public class ConcurrentMulticastSocket {
private final MulticastSocket sock;
/** Create a socket for sending. */
public ConcurrentMulticastSocket() throws IOException {
this.sock = new MulticastSocket();
}
/** Create a socket bound to the specified port for receiving. */
public ConcurrentMulticastSocket(int port) throws IOException {
this.sock = new MulticastSocket(port);
}
/** Join a multicast group. */
public synchronized void joinGroup(InetAddress mcastaddr) throws IOException {
sock.joinGroup(mcastaddr);
}
public synchronized void send(DatagramPacket p) throws IOException {
sock.send(p);
}
public synchronized void receive(DatagramPacket p) throws IOException {
sock.receive(p);
}
@Override
public String toString() {
return sock.getLocalSocketAddress().toString();
}
}
|