The JxtaMulticastSocket class is useful for sending and receiving JXTA multicast packets. A JxtaMulticastSocket is a (UDP) DatagramSocket, with additional capabilities for joining "groups" of other multicast hosts on the internet. A multicast group is specified within the context of PeerGroup and a propagate pipe advertisement. One would join a multicast group by first creating a MulticastSocket with the desired peer group and pipe advertisement :
// join a Multicast group and send the group salutations
...
String msg = "Hello";
MulticastSocket s = new JxtaMulticastSocket(peergroup, propPipeAdv);
//We are joined at this point
DatagramPacket hi = new DatagramPacket(msg.getBytes(), msg.length());
s.send(hi);
// get their responses!
byte[] buf = new byte[1000];
DatagramPacket recv = new DatagramPacket(buf, buf.length);
s.receive(recv);
...
// OK, I'm done talking - leave the group...
s.close();
One can also respond only to the sender of the datagram as follows :
DatagramPacket res = new DatagramPacket(response.getBytes(), response.length());
res.setAddress(recv.getAddress());
s.send(res);
When one sends a message to a multicast group, all subscribing recipients to that peergroup and pipe receive the message (including themselves) When a socket subscribes to a multicast group/port, it receives datagrams sent by other hosts to the group/pipe, as do all other members of the group and pipe. A socket relinquishes membership in a group by the close() method. Multiple MulticastSocket's may subscribe to a multicast group and pipe concurrently, and they will all receive group datagrams. When a datagram is sent it carries along with the peerid of the sender. The PeerID is represented as a InetAddress in the form of host/ipadress where host name is the peerid, and ip address is always represented as 0.0.0.0 since it is meaningless in the context of JXTA. e.g of InetAddress resembles the following:
uuid-59616261646162614A787461503250339C6014B0F21A49DBBDF2ADBDDBCB314703/0.0.0.0
分享到:
相关推荐
"解决 MyEclipse 8.5 中的 “Could not find the main class” 问题" "Could not find the main class" 是一个常见的错误提示,出现于 MyEclipse 8.5 中使用外带的 Tomcat 时,因 JDK 版本问题所引起。下面将详细...
在IT领域,尤其是在Java编程中,遇到“Can not find the main class. Program will exit.”这一错误信息是非常常见的问题。这通常意味着编译器或运行环境无法识别并定位到程序的主类,即包含main方法的类,从而导致...
### "Could Not Find the Main Class, Program Will Exit" 错误解析及解决方法 在Java编程过程中,我们经常会在开发环境中遇到各种各样的错误提示,其中“Could not find the main class, program will exit”是一...
### 关于“Retrieving the COM class factory for component with CLSID”问题详解 #### 背景介绍 在使用ASP .NET应用程序操作Excel、Word等Office软件时,有时会在IIS服务器上部署应用过程中遇到错误:...
两个CADODatabse class and the CADORecordset class,这是为了在C++中更好地进行ADO数据库操作 主要的类及其函数罗列如下: The CADODatabase Class CADODatabase Open Execute GetRecordsAffected ...
在Windows 7系统下运行Java应用包(JAR文件)时遇到“Could not find the main-class”错误,是常见的问题之一。这个问题通常出现在尝试启动一个没有正确指定主类的JAR文件时。主类是包含main方法的类,它是程序执行...
ComboBox Extending the ComboBox Class and Its Items.检查
### Win7下解决导出JAR包提示“can not find the main-class” #### 背景 在使用MyEclipse等开发工具进行Java程序开发时,我们常常会遇到需要将项目打包成JAR文件以便于分发或部署的情况。然而,在Windows 7系统下...
《Qt之"The Class"深入解析》 在编程领域,尤其是使用Qt框架进行开发时,类的设计与实现至关重要。本文将围绕“qt_class.rar_The Class”这一主题,深入探讨Qt中的类设计及其在Linux环境下的处理策略。我们将通过...
"TheClass"可能包含了关于图的一些属性,如节点、边、权重等,并提供了相应的操作,比如添加、删除节点或边,搜索路径,最短路径计算等。"graph"标签进一步证实了这一点,表明这个类可能实现了图数据结构或者与图...
NULL 博文链接:https://yintech.iteye.com/blog/374842
【标题】"the-universitys-class-design.zip_The Class" 提供的是一个关于软件开发中的类(Class)设计实例,可能包含一个大学课程项目或教学资料。这个压缩包可能涵盖了商品库存管理、二叉树遍历、面向对象编程中的...
《DTNSim.zip_The Class_the one simulator_the one模拟器》是关于"The One"模拟器的核心组件——"DTNSim.class"的详细解析。在这个压缩包中,我们重点关注的是一个名为"DTNSim"的类文件,它是"The One"模拟器运行的...
17.C++不仅仅是支持面向对象的程序设计语言; 18.学习编程最好的方法之一就是阅读源代码; 19.在任何时刻都不要认为自己手中... ... 20.请阅读《The Standard C++ Bible》(中文版:标准C++宝典),掌握C++标准;
Dynamic loading class in the java virtual machine
The implementation of the class-based utility to work with vectors.
This class defines the Service Provider Interface (<b>SPI< b>) for the CertificateFactory class.