Sent messages between two differt hosts

16 views
Skip to first unread message

Giuseppe Vacca

unread,
Nov 2, 2017, 5:31:41 PM11/2/17
to spade-users
Hi,
i have another problem.
I have sent a message between agent of the same AP, a sender and a receiver, and they work fine.

The two agents are:
RECEIVER
import os
import sys
import time
import unittest

import spade


class MyAgent(spade.Agent.Agent):
    class ReceiveBehav(spade.Behaviour.Behaviour):
        """This behaviour will receive all kind of messages"""
        def onStart(self):
            print "Behaviour di default .."
          
        def _process(self):
            self.msg = None
          
            # Blocking receive for 10 seconds
            self.msg = self._receive(True, 10)
          
            # Check wether the message arrived
            if self.msg:
                print "I got a message!"
            else:
                print "I waited but got no message"

    class AnotherBehav(spade.Behaviour.Behaviour):
        """This behaviour will receive only messages of the 'cooking' ontology"""
        def onStart(self):
            print "Behaviour per il modifing .."
          
        def _process(self):
            self.msg = None
          
            # Blocking receive indefinitely
            self.msg = self._receive(True)
          
            # Check wether the message arrived
            if self.msg:
                print "I got a modifing message!"
            else:
                print "I waited but got no modifing message"              

    def _setup(self):
        # Add the "ReceiveBehav" as the default behaviour
        rb = self.ReceiveBehav()
        self.addBehaviour(rb)
      
        # Prepare template for "AnotherBehav"
        cooking_template = spade.Behaviour.ACLTemplate()
        cooking_template.setOntology("modifing")
        mt = spade.Behaviour.MessageTemplate(cooking_template)

        # Add the behaviour WITH the template
        ab=self.AnotherBehav()
        self.addBehaviour(ab, mt)              

if __name__ == "__main__":
    print "Start the receiver ... "
    recv = MyAgent("re...@192.168.198.130", "secret")
    recv.start()

    alive = True
    import time
    print "Press any key ..."
    while alive:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            alive=False
          
    recv.stop()
    sys.exit(0)

SENDER
import spade
import os
import sys

class MyAgent(spade.Agent.Agent):
    class InformBehav(spade.Behaviour.OneShotBehaviour):

        def _process(self):
            msg = spade.ACLMessage.ACLMessage()
            msg.setPerformative("inform")
            msg.setOntology("modifing")
            msg.addReceiver(spade.AID.aid("re...@192.168.198.130",["xmpp://re...@192.168.198.130"]))
            msg.setContent("testSendMsg")

            self.myAgent.send(msg)

            print "a has sent a message:"
            print str(msg)
            print
            print self.myAgent.getPlatformInfo()
          
    def _setup(self):
        print "MyAgent starting . . ."
        b = self.InformBehav()
        self.addBehaviour(b, None)

if __name__ == "__main__":
    a = MyAgent("se...@192.168.198.130", "secret")
    a.start()
  
    alive = True
    import time
    print "Press Ctrl+C for exit."
    while alive:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            alive=False
  
    a.stop()
    sys.exit(0)


The problem is when the Send is on a different host with a different IP.
The new Sender on the host with IP 192.168.198.129 is:
import spade
import os
import sys

class MyAgent(spade.Agent.Agent):
    class InformBehav(spade.Behaviour.OneShotBehaviour):

        def _process(self):
            msg = spade.ACLMessage.ACLMessage()
            msg.setPerformative("inform")
            msg.setOntology("modifing")
            msg.addReceiver(spade.AID.aid("re...@192.168.198.130",["xmpp://re...@192.168.198.130"]))
            msg.setContent("testSendMsg")

            self.myAgent.send(msg)

            print "a has sent a message:"
            print str(msg)
            print
            print self.myAgent.getPlatformInfo()
          
    def _setup(self):
        print "MyAgent starting . . ."
        b = self.InformBehav()
        self.addBehaviour(b, None)

if __name__ == "__main__":
    a = MyAgent("se...@192.168.198.129", "secret")
    a.start()
  
    alive = True
    import time
    print "Press Ctrl+C for exit."
    while alive:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            alive=False
  
    a.stop()
    sys.exit(0)


... but not works.

Javi Palanca

unread,
Nov 6, 2017, 4:28:13 AM11/6/17
to spade...@googlegroups.com
Are you running two SPADE servers? Because what  is probably better is to run one server in one of the machines and both agents can connect to it, regardless of where they are executed. Take into account that the ip that is part of the AID of the agent is the location of the server, not the location of the agent.

However in the next version of SPADE, which will bring many changes and hopefully will be ready in a few months, I’m considering the option of not including the XMPP server inside the platform and delegate it to external servers, which are more up-to-date and efficient than the one included in SPADE, which is a toy-server.

Hope this helps.

best,
Javi

--
You received this message because you are subscribed to the Google Groups "spade-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spade-users...@googlegroups.com.
To post to this group, send email to spade...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Giuseppe Vacca

unread,
Nov 6, 2017, 4:47:12 AM11/6/17
to spade-users
Hi Javier,
yes, I'm running TWO Spade servers and my aim is to send a message between the two servers. I hoped that the XMP server of the two SPEDE servers
could connect ...

Thanks for answer and your excellent job !

Javi Palanca

unread,
Nov 6, 2017, 4:56:11 AM11/6/17
to spade...@googlegroups.com
Hi Giuseppe,

As I’ve said, the included XMPP server is a toy-server, and I think that s2s (server-to-server communications) does not work properly. sorry

Thanks for using spade.

best,
Javi
Reply all
Reply to author
Forward
0 new messages