def sending(queue,ADDR_SENDING,lock,commandqueue): net = NetworkUDP(ADDR_SENDING) #print queue while True: #print 'this is sending' sleep(0.1) #print "sending Thread" if lock.acquire(1) == True: if queue.empty() == False: msg = queue.get() lock.release() #print "sending ",msg if net.sending(msg[0], msg[1]) == False: #print "send",msg,"failed" #lock.release() print "Lost Connection From the Server" commandqueue.put("reset-all") #print "Send Success",msg if msg[0][0] == '@': break else: lock.release() return
def listening(queue,ADDR_LISTEN): net = NetworkUDP(ADDR_LISTEN) while True: msgdata, remote_addr = net.listening() print "GOT:",msgdata msgdata = msgdata.split('|') if msgdata[-1] == '#': msgdata.append(remote_addr) queue.put(msgdata) if msgdata[-1] == '@': break return
def listening(queue,ADDR_LISTEN,lock): net = NetworkUDP(ADDR_LISTEN) while True: msgdata, remote_addr = net.listening() #print "GOT:",msgdata msgdata = msgdata.split('|') if msgdata[-1] == '!': msgdata.append(remote_addr) lock.acquire() queue.put(msgdata) lock.release() if msgdata[-1] == '@': break return
def sending(queue,ADDR_SENDING,commandqueue): net = NetworkUDP(ADDR_SENDING) while True: msg = queue.get() #print "sending ",msg if net.sending(msg[0], msg[1])==False: print "send",msg,"failed" cmd = ["disconnect",str(msg[1][0]),str(msg[1][1])] cmd = " ".join(cmd) commandqueue.put(cmd) else: print "Send Success",msg if msg[0][0] == '@': break return