提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
UDP数据报套接字,多播发送器应用程序
/* from 时代Java*/ import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; public class Main { public static void main(String[] args) throws Exception { DatagramSocket udpSocket = null; udpSocket = new DatagramSocket(); InetAddress mcIPAddress = InetAddress.getByName("127.0.0.1"); byte[] msg = "Hello multicast socket".getBytes(); DatagramPacket packet = new DatagramPacket(msg, msg.length); packet.setAddress(mcIPAddress); packet.setPort(5555); udpSocket.send(packet); System.out.println(