def run(self):
        global central_server_ip
        while True:
            data = None
            try:
                data = self.client_conn.recv(self.size)
            except socket.error, e:
                print(e.message)

            if data is not None:
                try:
                    data = json.loads(data)
                    print("Received : " + str(data))
                    db_util = DBUtil()
                    db_util.update_database(data)
                except ValueError:
                    continue

                serv_addr = (central_server_ip, MASTER_PORT)
                tcp_sock = None
                msg = {'op' : 'ACK'}
                try:
                    tcp_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                    tcp_sock.connect(serv_addr)
                    tcp_sock.sendto(json.dumps(msg), serv_addr)
                    tcp_sock.close()
                except socket.error:
                    print("Error in socket")
                    if tcp_sock:
                        tcp_sock.close()

                continue

            self.client_conn.close()
            break
예제 #2
0
	def run(self):
		while True:
			dataRaw = None
			try:
				dataRaw = self.client_conn.recv(self.size)
				iv,dataEnc,dataHmac=dataRaw.split("nonce")
				dataAuth=verHmac(dataEnc,dataHmac)
				if not dataAuth:
					continue
				else:
					dataChecked=decrypt(dataEnc,iv)
			except socket.error, e:
				print(e.message)

			if dataRaw is not None:
				try:
					data = json.loads(dataChecked)
					print("Received : " + str(data))
					dbutil = DBUtil()
					self.sema.acquire()
					dbutil.update_database(data)
					self.sema.release()
				except ValueError:
					continue

			self.client_conn.close()
			break
    def run(self):
        while True:
            data = None
            try:
                data = self.client_conn.recv(self.size)
            except socket.error, e:
                print(e.message)

            if data is not None:
                try:
                    data = json.loads(data)
                    print("Received : " + str(data))
                    dbutil = DBUtil()
                    self.sema.acquire()
                    dbutil.update_database(data)
                    self.sema.release()
                except ValueError:
                    continue

            self.client_conn.close()
            break
예제 #4
0
    def run(self):
        while True:
            data = None
            try:
                data = self.client_conn.recv(self.size)
            except socket.error, e:
                print(e.message)

            if data is not None:
                try:
                    data = json.loads(data)
                    print("Received : " + str(data))
                    dbutil = DBUtil()
                    self.sema.acquire()
                    dbutil.update_database(data)
                    self.sema.release()
                except ValueError:
                    continue

            self.client_conn.close()
            break
예제 #5
0
    def run(self):
        global central_server_ip
        while True:
            data = None
            try:
                data = self.client_conn.recv(self.size)
            except socket.error, e:
                print(e.message)

            if data is not None:
                try:
                    data = json.loads(data)
                    print("Received : " + str(data))
                    db_util = DBUtil()
                    db_util.update_database(data)
                except ValueError:
                    continue

                serv_addr = (central_server_ip, MASTER_PORT)
                tcp_sock = None
                msg = {'op': 'ACK'}
                try:
                    tcp_sock = socket.socket(socket.AF_INET,
                                             socket.SOCK_STREAM)
                    tcp_sock.connect(serv_addr)
                    tcp_sock.sendto(json.dumps(msg), serv_addr)
                    tcp_sock.close()
                except socket.error:
                    print("Error in socket")
                    if tcp_sock:
                        tcp_sock.close()

                continue

            self.client_conn.close()
            break