summaryrefslogtreecommitdiff
path: root/test/java.net/MulticastClient.java
diff options
context:
space:
mode:
Diffstat (limited to 'test/java.net/MulticastClient.java')
-rw-r--r--test/java.net/MulticastClient.java65
1 files changed, 65 insertions, 0 deletions
diff --git a/test/java.net/MulticastClient.java b/test/java.net/MulticastClient.java
new file mode 100644
index 000000000..8dc18fe82
--- /dev/null
+++ b/test/java.net/MulticastClient.java
@@ -0,0 +1,65 @@
+/* Test Multicast Sockets */
+
+import java.net.*;
+import java.io.*;
+
+public class MulticastClient
+{
+
+public static void
+main(String[] argv) throws IOException
+{
+ System.out.println("Starting multicast tests");
+ System.out.println("NOTE: You need to do an 'ifconfig <interface> " +
+ "multicast' or this will fail on linux");
+
+ byte[] buf = { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o','r','l','d' };
+
+ /* Simple Send */
+ System.out.println("Test 1: Multicast send/receive test");
+ try
+ {
+ InetAddress addr = InetAddress.getByName("234.0.0.1");
+
+ MulticastSocket s = new MulticastSocket();
+ DatagramPacket p = new DatagramPacket(buf, buf.length, addr, 3333);
+
+ s.joinGroup(addr);
+ s.send(p);
+ s.close();
+ }
+ catch(IOException e)
+ {
+ System.out.println("FAILED: simple multicast send: " + e);
+ }
+
+ /* Options */
+ System.out.println("Test 2: Multicast socket options");
+ try
+ {
+ InetAddress addr;
+ MulticastSocket s = new MulticastSocket();
+
+ System.out.println("TTL = " + s.getTTL());
+ System.out.println("Setting TTT to 121");
+ s.setTTL((byte)12);
+ System.out.println("TTL = " + s.getTTL());
+
+ InetAddress oaddr = s.getInterface();
+ System.out.println("Multicast Interface = " + oaddr);
+ System.out.println("Setting interface to localhost");
+ addr = InetAddress.getByName("198.211.138.177");
+ s.setInterface(addr);
+ System.out.println("Multicast Interface = " + s.getInterface());
+ System.out.println("Setting interface to " + oaddr);
+ s.setInterface(oaddr);
+ System.out.println("Multicast Interface = " + s.getInterface());
+ }
+ catch(IOException e)
+ {
+ System.out.println("FAILED: multicast options: " + e);
+ }
+}
+
+}
+