Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JADE Platform Communication

Basically I'm trying the same thing as asked here: Passing ACL messages between jade remote platforms

I have two programmes creating two main container and an agent respectively. I run both programmes on different machines and want to send a message from one agent to another. The answer suggested in the question linked to above does not work for me. The receiver side always throws a java.lang.OutOfMemoryError and the sender shows this:

jade.mtp.MTPException: Description: ResponseMessage is not OK

Sending a message if both agents run in different agent containers on different machines but in the same main container works, but that's not what I try to achieve. Hope you can help me.

Code

Sender:

public class Main {

public static void main(String[] args) {

    Runtime runtime = Runtime.instance();

    Profile p = new ProfileImpl();
    p.setParameter(Profile.MAIN_HOST, "172.16.200.100");
    p.setParameter(Profile.MAIN_PORT, "1337");
    p.setParameter(Profile.CONTAINER_NAME,"Reality");

    AgentContainer agentContainer = runtime.createMainContainer(p);

    try {
        AgentController ac = agentContainer.createNewAgent("hitman",Agent47.class.getName(),null);
        ac.start();
        } catch (StaleProxyException e) {e.printStackTrace();}
    }
}

public class Agent47 extends Agent {

    private static final long serialVersionUID = 1L;

    @Override
    protected void setup() {

        ACLMessage msg = new ACLMessage(ACLMessage.INFORM); 
        AID dest = new AID("AgentSmith@Matrix",AID.ISGUID);
        dest.addAddresses("http://172.16.200.1:4242/acc");
        msg.addReceiver(dest);
        msg.setContent("Hello!");
        send(msg);
    }
}

Receiver:

public class Main {

    public static void main(String[] args) {
        Runtime runtime = Runtime.instance();

        Profile p = new ProfileImpl();              
        p.setParameter(Profile.MAIN_HOST, "172.16.200.1");
        p.setParameter(Profile.MAIN_PORT, "4242");
        p.setParameter(Profile.CONTAINER_NAME,"Matrix"); 

        AgentContainer agentContainer = runtime.createMainContainer(p);

        try {
            AgentController ac = agentContainer.createNewAgent("AgentSmith",AgentSmith.class.getName(),null);
            ac.start();
        } catch (StaleProxyException e) {e.printStackTrace();}
    }
}

public class AgentSmith extends Agent {

    private static final long serialVersionUID = 1L;

    @Override
    protected void setup() {

        addBehaviour(new CyclicBehaviour(this){

            private static final long serialVersionUID = 1L;

            public void action() {
                 ACLMessage  msg = myAgent.receive();
                    if(msg != null){

                            String content = msg.getContent();
                            if (content != null) {
                                System.out.println("Received Request from "+msg.getSender().getLocalName());
                                System.out.println("Received Message : "+content);
                            }

                        }  
             }
        });

        System.out.println("Setup done!");
    }

}
like image 831
Rick Avatar asked Nov 19 '25 18:11

Rick


1 Answers

Worked something out. In case others have the same problems, here my solution: I had to set the platform IP and also the IP for the MTP host.

String host = "172.16.200.100"; // Platform IP
int port = 1099; // default-port 1099

String MTP_hostIP = "172.16.200.100"; 
String MTP_Port = "7778";

Runtime runtime = Runtime.instance();

Profile profile = new ProfileImpl(host, port, null, true);  
profile.setParameter(Profile.MTPS, "jade.mtp.http.MessageTransportProtocol(http://"+MTP_hostIP+":"+MTP_Port+"/acc)");

// create container
AgentContainer container = runtime.createMainContainer(profile);

try {
    AgentController ac = container.createNewAgent("AgentSmith",AgentSmith.class.getName(),null);
    ac.start();
} catch (StaleProxyException e) {
    e.printStackTrace();
}

It also turned out that, if I used localhost for the host IP and the network IP for the MTP host, the communication would not properly work in my class B network. Setting both variables to the same IP solved that.

like image 98
Rick Avatar answered Nov 22 '25 08:11

Rick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!