使用DatagramSocket创建多播发件人
import java.io.*; import java.net.*; /*来自 时代Java公众号 - nowjava.com*/ public class MulticastSender { public static void main(String[] args) { byte[] outBuf; final int PORT = 8888; try { DatagramSocket socket = new DatagramSocket(); long counter = 0; String msg; /**来自 nowjava - 时代Java**/ while (true) { msg = "This is multicast! " + counter; counter++; outBuf = msg.getBytes(); //Send to multicast IP address and port InetAddress address = InetAddress.getByName("224.2.2.3"); DatagramPacket outPacket = new DatagramPacket(outBuf, outBuf.length, address, PORT); socket.send(outPacket); System.out.println("Server sends : " + msg); try {