def run(self): # As long as we weren't asked to stop, try to take new data from the # queue. The tasks are taken with a blocking 'get', so no CPU # cycles are wasted while waiting. print "forwarder Started" try: client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) except socket.error: print 'Failed to create socket' return loead_clients = True while True: if loead_clients: clients = config.getClients(db_name) c_id = {} for r in clients: if r[0] in c_id: c_id[r[0]].append([r[1], r[2]]) else: c_id[r[0]] = [[r[1], r[2]]] loead_clients = False print "Reading" message = self.fwd_q.get() print "BBBBBBBBBB" + str(message.data) if message is None: # This will probably never reached print "None Received" continue # self.writeLog(message) print "forwarder", message.data if message.data == "%": break if message.data[0] == '#' and message.data[-1] == ';': col = message.data[1:-1].split(',') target_clients = [] if col[0] in c_id: target_clients = target_clients + c_id[col[0]] if "*" in c_id: target_clients = target_clients + c_id["*"] for client in target_clients: try: client_socket.settimeout(2) print "M2 sent is: " + message.data client_socket.sendto(message.data, (client[0], client[1])) print "Sending to", client[0], client[1] except socket.error, msg: print 'Error Code : ' + str( msg[0]) + ' Message ' + msg[1] except socket.timeout: print("Timeout")
def run(self): # As long as we weren't asked to stop, try to take new data from the # queue. The tasks are taken with a blocking 'get', so no CPU # cycles are wasted while waiting. print "forwarder Started" try: client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) except socket.error: print 'Failed to create socket' return loead_clients = True while True: if loead_clients: clients = config.getClients(db_name) c_id = {} for r in clients: if r[0] in c_id: c_id[r[0]].append([r[1],r[2]]) else: c_id[r[0]] = [[r[1],r[2]]] loead_clients = False print "Reading" message = self.fwd_q.get() print "BBBBBBBBBB" + str(message.data) if message is None: # This will probably never reached print "None Received" continue # self.writeLog(message) print "forwarder", message.data if message.data == "%": break; if message.data[0] == '#' and message.data[-1] == ';': col = message.data[1:-1].split(',') target_clients = [] if col[0] in c_id: target_clients = target_clients + c_id[col[0]] if "*" in c_id: target_clients = target_clients + c_id["*"] for client in target_clients: try : client_socket.settimeout(2) print "M2 sent is: " + message.data client_socket.sendto(message.data, (client[0], client[1])) print "Sending to" ,client[0], client[1] except socket.error, msg: print 'Error Code : ' + str(msg[0]) + ' Message ' + msg[1] except socket.timeout: print("Timeout")