java multicast demo

 

import java.net.DatagramPacket;  
import java.net.InetAddress;  
import java.net.MulticastSocket;  
import java.net.NetworkInterface;
  
public class Multicast {  
    public static void main(String[] args) throws Exception {  
        byte[] data = new byte[256];  
        MulticastSocket s = new MulticastSocket();  
        s.setNetworkInterface(NetworkInterface.getByInetAddress(InetAddress.getByName("192.168.29.1")));
        s.setTimeToLive(32);  
        DatagramPacket pkt = new DatagramPacket(data, data.length, InetAddress  
                .getByName("225.1.1.1"), 32000);  
        s.send(pkt);  
    }  
}  

你可能感兴趣的:(multicastsocket)