服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

jade:远程机器的agent通信应注意的问题

要实现局域网内不同机器上的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("http://gjpc:7778/acc");
          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<agents.length;i++){
            if ( agents[i].getname().equals(getaid()) ){
                continue;
            }
            system.out.println(agents[i].getname().tostring());
            agents[i].getname().addaddresses("http://gjpc:7778/acc");
            //这一句必须要有
            msg.addreceiver( agents[i].getname() );
        
        }
        
        system.out.println("wait fro a minute...");
        
    
        
        send(msg);
    }

}

扫描关注微信公众号