41 import java.nio.channels.*;
42 import java.nio.charset.Charset;
44 import java.io.IOException;
55 System.err.println(
"usage: java Sender group:port[@interface] message");
59 public static void main(String[] args)
throws IOException {
66 ProtocolFamily family = StandardProtocolFamily.INET;
67 if (target.
group() instanceof Inet6Address)
68 family = StandardProtocolFamily.INET6;
69 DatagramChannel dc = DatagramChannel.open(family).bind(
new InetSocketAddress(0));
70 if (target.
interf() !=
null) {
71 dc.setOption(StandardSocketOptions.IP_MULTICAST_IF, target.
interf());
75 dc.send(Charset.defaultCharset().encode(args[1]),
76 new InetSocketAddress(target.
group(), target.
port()));