文件名称:Java发送、接受数据-组播实例.rar
文件大小:4KB
文件格式:RAR
更新时间:2022-07-30 05:21:53
Java源码-网络相关
Java发送、接受数据-组播实例,String groupHost="232.0.0.1"; //组播组虚拟IP int port=5678;//端口 public MulticastServer(){ try{ MulticastSocket multicastSocket = new MulticastSocket(port); //MulticastSocket实例 InetAddress inetAddress = InetAddress.getByName(groupHost); //组地址 multicastSocket.joinGroup(inetAddress); //加入到组播组中 while (true){ byte[] received = new byte[128]; //接收数据缓冲 DatagramPacket datagramPacket = new DatagramPacket(received, received.length); //接收数据的数据报 multicastSocket.receive(datagramPacket); //接收数据 System.out.println(new String(received)); //输出接收到的数据
【文件预览】:
codesc.net
----Java 组播组中发送和接受数据()
--------MulticastClient.java(833B)
--------MulticastClient.class(889B)
--------MulticastServer.java(929B)
--------MulticastServer(750B)
--------MulticastServer.class(1KB)