Message send receive not working

63 views
Skip to first unread message

Swati Deshkar

unread,
Jan 26, 2016, 12:03:32 AM1/26/16
to spade-users
Hello,

      I am trying to execute send and receive message code. The PC will send the message to Intel galileo processor. The code run for the first time but when I executed later, it didn't work. I dont know why???? .
              Below are the Sender and Receiver codes. Please tell me whats going wrong with these codes.

Sender
 
import spade
   
class Sender(spade.Agent.Agent):
 
    def _setup(self):
        self.addBehaviour(self.SendMsgBehav())
        print "Sender started!"
 
    class SendMsgBehav(spade.Behaviour.OneShotBehaviour):
 
        def _process(self):
            msg = spade.ACLMessage.ACLMessage()
            msg.setPerformative("inform")
            msg.addReceiver(spade.AID.aid("b@IPaddress of galileo",["xmpp://b@IPaddress of galileo"]))
            msg.setContent("testSendMsg")
 
            self.myAgent.send(msg)
            print "a has sent a message:"
            print str(msg)
            self.myAgent.stop()
       
   
a = Sender("a@IPaddress of PC","secret")
a.start()
 

  Receiver

import spade
 
class Receiver(spade.Agent.Agent):
 
    class RecvMsgBehav(spade.Behaviour.OneShotBehaviour):
 
        def _process(self):
            msg = self._receive(block=True,timeout=10)
            print "b has received a message:"
            print str(msg)
            self.myAgent.stop()
   
 
    def _setup(self):
        template = spade.Behaviour.ACLTemplate()
        template.setSender(spade.AID.aid("a@IPaddress of PC",["xmpp://a@IPaddress of PC"]))
        t = spade.Behaviour.MessageTemplate(template)
        self.addBehaviour(self.RecvMsgBehav(),t)
        print "Receiver started!"
 
 
b = Receiver("b@IPaddress of galileo","secret") 
b.start()

 

Javi Palanca

unread,
Jan 27, 2016, 9:30:42 AM1/27/16
to spade...@googlegroups.com
Hi Swati.

A OneShotBehaviour runs once and then dies. So it can't work two times (unless you restart the agent itself or the behavior).
What you probably need in the receiver is a cyclic behavior (spade.Behavior.Behaviour) which runs in a permanent loop or a behavior based on events (spade.Behavior.EventBehaviour) which is run every time its template matches with a received message.

If you are restarting the agent (I guess you are, since the receiver behavior stops the agent) it may be a problem with the registration and/or authentication of the agents. Is there any error message shown in console?

Hope this helps.
Sincelery,
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.

Swati Deshkar

unread,
Jan 29, 2016, 8:10:01 AM1/29/16
to spade-users
Thanks  Javi,
                    One more thing I want to ask is that - Is there any way in the spade platform to send the message between two agents running on the different spade platforms (for ex- spade platform with ip address1 and another spade platform with IP address2) ?


Reply all
Reply to author
Forward
0 new messages