 |
|
|
MultiClient.java
|
/*
* Author: Havard Rast Blok
* E-mail:
* Web : www.rememberjava.com
*/
import java.net.*;
/**
* A simple multicast client.
*/
public class MultiClient
{
public MultiClient ()
{
String msg = "Hello there! Can you hear me?";
InetAddress group;
MulticastSocket s;
DatagramPacket hi;
try
{
// join a Multicast group and send the group salutations
group = InetAddress.getByName("228.5.6.7");
s = new MulticastSocket(6789);
s.joinGroup(group);
hi = new DatagramPacket(msg.getBytes(), msg.length(), group, 6789);
s.send(hi);
// OK, I'm done talking - leave the group...
s.leaveGroup(group);
}
catch(Exception e )
{
System.out.println("MultiServer - Exception: "+e);
}
}
public static void main( String args[] )
{
new MultiClient();
}
}
|
|
|
 |