OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [test/] [java.net/] [MulticastClient.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* Test Multicast Sockets */
2
 
3
import java.net.*;
4
import java.io.*;
5
 
6
public class MulticastClient
7
{
8
 
9
public static void
10
main(String[] argv) throws IOException
11
{
12
  System.out.println("Starting multicast tests");
13
  System.out.println("NOTE: You need to do an 'ifconfig <interface> " +
14
                     "multicast' or this will fail on linux");
15
 
16
  byte[] buf = { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o','r','l','d' };
17
 
18
  /* Simple Send */
19
  System.out.println("Test 1: Multicast send/receive test");
20
  try
21
    {
22
      InetAddress addr = InetAddress.getByName("234.0.0.1");
23
 
24
      MulticastSocket s = new MulticastSocket();
25
      DatagramPacket p = new DatagramPacket(buf, buf.length, addr, 3333);
26
 
27
      s.joinGroup(addr);
28
      s.send(p);
29
      s.close();
30
    }
31
  catch(IOException e)
32
    {
33
      System.out.println("FAILED: simple multicast send: " + e);
34
    }
35
 
36
  /* Options */
37
  System.out.println("Test 2: Multicast socket options");
38
  try
39
    {
40
      InetAddress addr;
41
      MulticastSocket s = new MulticastSocket();
42
 
43
      System.out.println("TTL = " + s.getTTL());
44
      System.out.println("Setting TTT to 121");
45
      s.setTTL((byte)12);
46
      System.out.println("TTL = " + s.getTTL());
47
 
48
      InetAddress oaddr = s.getInterface();
49
      System.out.println("Multicast Interface = " + oaddr);
50
      System.out.println("Setting interface to localhost");
51
      addr = InetAddress.getByName("198.211.138.177");
52
      s.setInterface(addr);
53
      System.out.println("Multicast Interface = " + s.getInterface());
54
      System.out.println("Setting interface to " + oaddr);
55
      s.setInterface(oaddr);
56
      System.out.println("Multicast Interface = " + s.getInterface());
57
    }
58
  catch(IOException e)
59
    {
60
      System.out.println("FAILED: multicast options: " + e);
61
    }
62
}
63
 
64
}
65
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.