要实现局域网内不同机器上的Agent进行通信,需要注意这样两个问题:
1。防火墙内关于文件与打印机共享的协议必须打开,保证机器名的解析。
2。通信时ACLMessage添加Receiver的时候指定合法的AID,这个AID一要有完整的名称,二要有合法的Addresses。
比如下面的例子
import jade.core.AID;
import jade.domain.AMSService;
import jade.domain.FIPAAgentManagement.*;
public class Sender2 extends Agent {
protected void setup()
{
AMSAgentDescription [] agents = null;
AID Rams= new AID("ams@gjpc:1099/JADE");//获取gjpc机器上的ams
Rams.addAddresses("");
try {
SearchConstraints c = new SearchConstraints();
c.setMaxResults (new Long(-1));
//agents = AMSService.search( this, new AMSAgentDescription (), c );
//下面查找rams里面的agents
agents = AMSService.search( this, Rams, new AMSAgentDescription (), c );
}
catch (Exception e) {
System.out.println( "Problem searching AMS: " + e );
e.printStackTrace();
}
ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
msg.setContent( "this is from guojie 's Ping" );//本地机器名为guojie
//逐个向他们发送消息
for (int i=0; i
if ( agents[i].getName().equals(getAID()) ){
continue;
}
System.out.println(agents[i].getName().toString());
agents[i].getName().addAddresses("");//这一句必须要有
msg.addReceiver( agents[i].getName() );
}
System.out.println("wait fro a minute...");
send(msg);
}
}
阅读(3064) | 评论(1) | 转发(0) |