예제 #1
0
    def handle(self):
        try:
            while True:
                data = self.request.recv(BUFSIZ)
                print("{} send:".format(self.client_address), data)
                logger.info(data)
                if not data:
                    print("connection lost:{}".format(self.client_address))
                    logger.info("connection lost:{}".format(
                        self.client_address))
                    break
                parsedate = getparsedate(data)
                if isinstance(parsedate, Exception):
                    rtnstr = '请传入正确的JSON字符串'
                    logger.error(rtnstr)
                    self.request.sendall(rtnstr.encode('GBK'))
                    continue

                rtnstr = checkbarcode(parsedate)
                if rtnstr == 'OK':
                    rtnstr = savetestdata(parsedate)

                self.request.sendall(rtnstr.encode('GBK'))

        except Exception as e:
            logger.error(e)
            print(self.client_address, "连接断开")
        finally:
            self.request.close()
예제 #2
0
def getparsedate(msg):
    msg_str = msg.decode('GBK').replace(b'\x00'.decode(),'')
    logger.info(msg_str)
    try:
        msg_dic = json.loads(msg_str)
    except JSONDecodeError as e:
        logger.error(e)
        return e
    return msg_dic
예제 #3
0
 def finish(self):
     print("finish run  after handle")
     logger.info("finish run  after handle")
예제 #4
0
 def setup(self):
     print("before handle,连接建立:", self.client_address)
     logger.info("before handle,连接建立:{}".format(self.client_address))