快速业务通道

使用Java制作多点发送程序 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-22
       System.exit(1);        }        while (keepReceiving) {        try {         // Create a new datagram.         mulcastBuffer = new byte[DATAGRAM_BYTES];         mulcastPacket = new DatagramPacket(mulcastBuffer, mulcastBuffer.length);         // Receive the datagram.         mulcastSocket.receive(mulcastPacket);         fromIP = mulcastPacket.getAddress();         fromPort = mulcastPacket.getPort();         mulcastMsg = new String(mulcastPacket.getData());         // Print out the data.         System.out.println("Received from " + fromIP + " on port " + fromPort + ": " + mulcastMsg);        } catch(IOException excpt) {        system.err.println("Failed I/O: " + excpt);        }       }      try {       mulcastSocket.leaveGroup(mulcastIP); file:// Leave the group.        } catch(IOException excpt) {       System.err.println("Socket problem leaving group: " + excpt);      }      mulcastSocket.close();    // Close the socket.      }     public void stop() {      if (keepReceiving) {       keepReceiving = false;       }      }     }

使用Java制作多点发送程序(4)

时间:2010-12-25 yesky 林建刚

若要运用该应用程序,先编译MultiCastSender和MultiCastReceiver,然后将MultiCastReceiver传送到其它机器,以便能够演示多个参与者接收报文的情况,最后Java解释器运行该应用程序。例如:要向225.2.32.6组在端口1111上发送多点发送报文,应按如下方法进行:

-/class ->java MultiCastSender225.2.32.6 1111

Here is just to test multicast message.

Sending: Here is just to test multicast message.

Do you received it?

Sending: Do you received it?

要接收这些报文,应在一个或多个系统上运行MultiCastReceiver应用程序,这些系统应该加入同一个多点发送组225.2.32.6,并在相同的端口1111上侦听:

-/class ->java MultiCastReceiver 225.2.32.6 1111

Received from 225.106.36.32 on port 32911: Here is just to test multicast message.

Received from 225.106.36.32 on port 32911: Do you received it?

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号