def _process(self): sleep(2) msg = ACLMessage() msg.setPerformative("request") msg.addReceiver( AID.aid("external@" + self.myAgent.host, ["http://" + self.myAgent.host + ":1099/JADE"])) msg.setSender(self.myAgent.getAID()) msg.setContent("MESSAGE") self.myAgent.send(msg) print "SENT HTTP MESSAGE"
def _process(self): sleep(2) msg = ACLMessage() msg.setPerformative("request") msg.addReceiver(AID.aid("external@"+self.myAgent.host, ["http://"+self.myAgent.host+":1099/JADE"])) msg.setSender(self.myAgent.getAID()) msg.setContent("MESSAGE") self.myAgent.send(msg) print "SENT HTTP MESSAGE"
def send_report(self, agent_name): report_messages = self.myAgent.reports[agent_name] receiver = AID.aid(name=agent_name, addresses=["xmpp://" + agent_name]) message = ACLMessage.ACLMessage() message.addReceiver(receiver) message.setOntology("report_delivery") message.setContent(json.dumps([obj.__dict__ for obj in report_messages])) self.myAgent.send(message)
def __send_tweet_message(self, tweet): message = ACLMessage.ACLMessage() message.addReceiver(self.myAgent.receiver) message.setOntology("notify") object = ReportMessage("Twitter", self.myAgent.fetch_type, self.myAgent.keyword, tweet.username, tweet.name, tweet.date, tweet.text) value = json.dumps(object.__dict__) message.setContent(value) self.myAgent.send(message)
def __send_status_message(self, post): message = ACLMessage.ACLMessage() message.addReceiver(self.myAgent.receiver) message.setOntology("notify") object = ReportMessage("Facebook", post.status_type, self.myAgent.keyword, post.username, post.name, post.date, post.message + " (" + post.link + ")") value = json.dumps(object.__dict__) message.setContent(value) self.myAgent.send(message)
def getContent(self, rfile, boundary, clen): """ Parses entity body catching the envelope and payload of the incoming message """ env = None pay = None part = 0 buf1 = rfile.read(int(clen)).split(BI + boundary + BI) if len(buf1) != 2: self.send_error(400, "Malformed Multipart-Mixed MIME") buf2 = buf1[0].split(BI + boundary) parts = len(buf2) try: if parts == 2: env = buf2[0] pay = buf2[1] elif parts == 3: # there is text before the first boundary delimiter line, and it is ignored env = buf2[1] pay = buf2[2] else: self.send_error(400, "Malformed Multipart-Mixed MIME") except: self.send_error(400, "Malformed Multipart-Mixed MIME") # searching CLRF CLRF where envelope really starts, before this sequence is the envelope content type index = env.find('\r\n\r\n') if index < 0: index = env.find('\n\n') type_env = env[0:index] env = env[index + 2:] # the same for payload index = pay.find('\r\n\r\n') if index < 0: index = pay.find('\n\n') type_pay = pay[0:index] pay = pay[index + 2:] # Content types check try: type_env = type_env.split(':')[1].split(';')[0].strip() type_pay = type_pay.split(':')[1].split()[0].strip() except: #self.send_error(415) pass #if str(FIPA_CT_ENV) not in str(type_env) or str(FIPA_CT_PAY) not in str(type_pay): # if str(CT_XML) not in str(type_env) or str(CT_TEXT) not in str(type_pay): # print type_env, type_pay # self.send_error(415) if type_env == FIPA_CT_ENV or type_env == CT_XML: # parsing the envelope xc = XMLCodec.XMLCodec() env = env.strip("\r\n") try: envelope = xc.parse(env) except Exception: self.send_error(400, "Malformed FIPA Envelope") elif type_env == CT_JSON: envelope = Envelope.Envelope(jsonstring=env) else: self.send_error(415) return None, None if FIPA_CT_PAY in type_pay or CT_TEXT in type_pay: p = ACLParser.ACLParser() try: payload = p.parse(pay) except Exception: self.send_error(400, "Malformed FIPA ACL Payload") return envelope, None elif type_pay == CT_XML or type_pay == "application/" + ACLMessage.FIPA_ACL_REP_XML: p = ACLParser.ACLxmlParser() try: payload = p.parse(pay) except Exception: self.send_error(400, "Malformed FIPA XML Payload") return envelope, None elif type_pay == CT_JSON: payload = ACLMessage.ACLMessage(jsonstring=pay) else: self.send_error(415) return envelope, None return (envelope, payload)
return (envelope, payload) #Required constants PROTOCOL = "http" INSTANCE = http if __name__ == "__main__": http_mtp = http("SpadeHttpSever", None, None) import time time.sleep(5) msg = ACLMessage.ACLMessage() msg.setPerformative("inform") msg.addReceiver(AID.aid("b@localhost", ["xmpp://b@localhost", "http://*****:*****@localhost", ["xmpp://b@localhost", "http://*****:*****@localhost", ["xmpp://a@localhost", "http://localhost:2099/a"])) env.setAclRepresentation(ACLMessage.FIPA_ACL_REP_XML) env.setPayloadEncoding("US-ASCII") env.setDate("20121105T134259368626") http_mtp.send(env, msg) """
def sendFIPAMsg(self, to, performative, content): msg = ACLMessage.ACLMessage() msg.addReceiver(to) msg.setPerformative(performative) msg.setContent(content)
def __send_report_message(self): message = ACLMessage.ACLMessage() message.addReceiver(self.myAgent.receiver) message.setOntology("report") message.setContent(self.myAgent.getName()) self.myAgent.send(message)