Example #1
0
    def connect(self, event):
#       info = InputDialogMulti(self.master, event, "Qual o ip?", "Qual a porta?")
#       self.master.wait_window(info.top)
        contexto = zmq.Context()
        socketEnvio = contexto.socket(zmq.PUSH)
        socketResposta = contexto.socket(zmq.PULL)
        ip, porta = self.strMainIp.get(), self.strMainPort.get()
        socketResposta.bind("tcp://" + getIp() + ":" + porta)
        print "Tentando conexão com {}:{}".format(ip, porta)
        socketEnvio.connect("tcp://" + ip + ":" + porta)
        print "Conexão estabelecida, enviando mensagem "
        socketEnvio.send("olá sou o " + getIp())
        print "Aguardando resposta..."
        tentativas = 0
        while tentativas < 1000:
            msg = None
            try:
                msg = socketResposta.recv(zmq.NOBLOCK)
            except zmq.ZMQError:
                tentativas += 1
            if msg != None:
                print 'msg'
                self.writeLog("recebi " + msg + '\n')
                break
            time.sleep(0.01)
        print 'quitei'
        del socketResposta
        del socketEnvio
        print 'mesmo'
        return
Example #2
0
    def connect(self, event):
#       self.txtLog.insert(tk.END, "connect")
        if (int(self.numAssistants.get()) <= 0):
            tkmessage.showwarning("Atenção", "Informe a quantidade de assistentes.")
            return False
#       self.txtLog.insert(tk.END, "connect")
        porta = self.connectPort.get()
        contexto = zmq.Context()
        socketResponder = []
        socketRequisicoes = contexto.socket(zmq.PULL)
        self.writeLog("bind em tcp://" + getIp() + ":" + porta + '\n')
        socketRequisicoes.bind("tcp://" + getIp() + ":" + porta)
        self.writeLog("aguardando requisições...\n")
        print 'são ', self.numAssistants.get()
        tentativas = 0
        numAssistants = int(self.numAssistants.get())
        self.assistantasIps = []
        while tentativas < 1000 and len(socketResponder) < numAssistants:
            socketRequisicoes.setsockopt(zmq.LINGER, 1)
            msg = None
            try:
                msg = socketRequisicoes.recv(zmq.NOBLOCK)
            except zmq.ZMQError:
                tentativas += 1
            if msg != None:
                tentativas = 0
                self.writeLog(str(len(socketResponder)+1) + ": ")
                self.writeLog("recebi " + msg + '\n')
                socketResponder.append(contexto.socket(zmq.PUSH))
                self.assistantasIps.append(msg.split()[-1])
                socketResponder[-1].connect("tcp://" + msg.split()[-1] + ":" + porta)
                socketResponder[-1].send("e aí mano, blz? seu id é:"+ str(len(socketResponder)))
            time.sleep(0.01)
        if len(socketResponder) != numAssistants:
            self.writeLog("tempo de espera limite atingido\n")
        else:
            print self.assistantasIps
Example #3
0
 def fillConfiguration(self):
     configuration = {}
     configuration["baseIp"] = getIp()
     configuration["baseDir"] = self.strBaseDirectory.get()
     configuration["agentsPort"] = self.strAgentsPorts.get()
     configuration["monitorPort"] = self.strMonitorPort.get()
     configuration["strategyPort"] = self.strStrategyPort.get()
     configuration["agents"] = []
     for stringVar in self.agents["str"]:
         configuration["agents"].append(stringVar.get())
     configuration["environ"] = self.strLaunchEnviron.get()
     configuration["tester"] = self.strLaunchTester.get()
     configuration["monitor"] = self.strLaunchMonitor.get()
     configuration["strategy"] = self.strLaunchStrategy.get()
     # FIXME: incompleto!
     # prepareConfiguration(configuration)
     return configuration