def spreadTheWord(dataJSON): print bcolors.Magenta + 'I{} said that he subscribes {}... updating the route list'.format(dataJSON['id'], dataJSON['data']) + bcolors.ENDC intermedList.append(dataJSON) newData = copy.deepcopy(dataJSON) if interId == 2: newData['name'] = 'intermed' newData['id'] = '2' newJSON = json.dumps(newData) sendmessage(host, i1port, newJSON)
def btnSend(self): """ Takes the current text from the textbox and servers it to the server as a string and displays the return message""" if self.SubmitTextBox.get("1.0", "end-1c") == "": return tk.Label(self.pnlChatContent, text=self.SubmitTextBox.get("1.0", "end-1c"), justify=tk.LEFT, wraplength=200, anchor="nw", width=200).grid(column=1, sticky="nw", pady=5) #messagebox.showinfo(None,self.SubmitTextBox.get("1.0","end-1c")) self.returnmsg = sendmessage(self.SubmitTextBox.get("1.0", "end-1c")) tk.Label(self.pnlChatContent, text=self.returnmsg, justify=tk.LEFT, wraplength=200, anchor="nw", width=30).grid(column=0, sticky="nw", pady=5) while self.SubmitTextBox.get( "1.0", "end-1c" ) != "": # Loops through the textbox untill the textbox is empty self.SubmitTextBox.delete(1.0) self.objApp.window.update() self.Scrollwin()
def expressIntention(dataJSON): intermedList.append(dataJSON) newData = copy.deepcopy(dataJSON) print bcolors.Cyan + 'S{} said that subscribes {}'.format(dataJSON['id'], dataJSON['data']) + bcolors.ENDC if interId == 2: newData['name'] = 'intermed' newData['id'] = '2' newJSON = json.dumps(newData) sendmessage(host, i1port, newJSON) sendmessage(host, i3port, newJSON) elif interId == 3: newData['name'] = 'intermed' newData['id'] = '3' newJSON = json.dumps(newData) sendmessage(host, i2port, newJSON)
def seeOnList(dataJSON): c = None if len(intermedList) == 0 : print bcolors.Red + 'nothing to be subscribed yet' + bcolors.ENDC else: count = 0 for l in intermedList: if(l['data'] == dataJSON['data']): count += 1 print bcolors.Yellow + 'Someone has interest on this publication' + bcolors.ENDC if interId == 1: print bcolors.White + 'I2 wants the publication... Sending to I2' + bcolors.ENDC sendmessage(host, i2port, json.dumps(dataJSON)) elif interId == 2: if l['name'] == 'intermed' and l['id'] == '3': print bcolors.White + 'I3 wants the publication... Sending to I3' + bcolors.ENDC sendmessage(host, i3port, json.dumps(dataJSON)) elif l['name'] == 'subscriber' and l['id'] == '1': print bcolors.White + 'S1 wants the publication... Sending to S1' + bcolors.ENDC sendmessage(host, s1port, json.dumps(dataJSON)) elif l['name'] == 'subscriber' and l['id'] == '2': print bcolors.White + 'S2 wants the publication... Sending to S2' + bcolors.ENDC sendmessage(host, s2port, json.dumps(dataJSON)) elif interId == 3: if l['name'] == 'intermed' and l['id'] == '2': print bcolors.White + 'I2 wants the publication... Sending to I2' + bcolors.ENDC sendmessage(host, i2port, json.dumps(dataJSON)) elif l['name'] == 'subscriber' and l['id'] == '3': print bcolors.White + 'S3 wants the publication... Sending to S3' + bcolors.ENDC sendmessage(host, s3port, json.dumps(dataJSON)) if count == 0: print bcolors.Red + 'No one subscribes this data' + bcolors.ENDC
s1port = 8094 s2port = 8095 s3port = 8096 pubId = '' pubName = '' pubPort = 0 parser = argparse.ArgumentParser(description='Create intermediate process') parser.add_argument('publisher', metavar='N', type=int, nargs=1, help='the publisher number [1 or 2]') args = parser.parse_args() if args.publisher[0] == 1: print 'initializing P1' pubName = 'P1' pubId = '1' pubPort = i1port elif args.publisher[0] == 2: print 'initializing P2' pubName = 'P2' pubId = '2' pubPort = i3port while 1: pubData = raw_input(bcolors.BOLD + 'What to pub with {} ?: '.format(pubName) + bcolors.ENDC) pubJSON = json.dumps({'name':'publisher', 'id':pubId,'data':pubData}) sendmessage(host, pubPort, pubJSON) print 'Publishing with {} the data {}'.format(pubName, pubData)