import socket import threading import json import config as cfg class Connection(threading.Thread): def __init__(self,connection,address,oracleSocketPort,typee): super(Connection,self).__init__(None, None, None, None) self.conn = connection self.addr = address self.history = [] self.type = typee self.oracleSocketPort = oracleSocketPort t = threading.Thread(target=self.receive) t.start() # self.send("Connection") def toSEND(self, data): j = json.dumps(x) l = LenFunc - len(str(len(j))) self.send("0000"[0:l]+str(len(j))+j) def send(self,Message): Message=bytes(Message,'utf-8') self.conn.sendall(Message) # self.history.append(("send",Message)) def receive(self): while True: len = self.conn.recv(cfg.LenFunc) if not len: break data = self.conn.recv(int(len)) print("data",data) self.type.parser(data.decode("utf-8"),self.conn) # self.history.append(("receive",data))