def run(self):
    response = '接收成功，返回数据: connecting status: 200 \n'
    response += 'haody,client ! | '
    while self.inputs:
        print('waiting for next event')
        (readable, writable, exceptional) = select.select(self.inputs, self.outputs, self.inputs, self.timeout)
        if (not (readable or writable or exceptional)):
            print('Time out ! ')
            break
        for ser in readable:
            if (ser is self.server):
                (connection, client_address) = ser.accept()
                print('connection from ', client_address)
                connection.setblocking(0)
                self.inputs.append(connection)
                self.message_queues[connection] = queue.Queue()
            else:
                data = ser.recv(1024)
                if data:
                    print('收到数据 ', data.decode(), '\n来自:', ser.getpeername())
                    self.message_queues[ser].put(data)
                    if (ser not in self.outputs):
                        self.outputs.append(ser)
                else:
                    print('closing', client_address)
                    if (ser in self.outputs):
                        self.outputs.remove(ser)
                    self.inputs.remove(ser)
                    ser.close()
                    del self.message_queues[ser]
        for ser in writable:
            try:
                next_msg = self.message_queues[ser].get_nowait()
            except queue.Empty:
                print(ser.getpeername(), 'queue empty')
                self.outputs.remove(ser)
            else:
                print('发送数据 ', str((response + next_msg.decode())), ' to ', ser.getpeername(), '\n')
                ser.send((response.encode() + next_msg))
        for ser in exceptional:
            print(' exception condition on ', ser.getpeername())
            self.inputs.remove(ser)
            if (ser in self.outputs):
                self.outputs.remove(ser)
            ser.close()
            del self.message_queues[ser]
def run(self):
    response = '接收成功，返回数据: connecting status: 200 \n'
    response += 'haody,client ! | '
    while self.inputs:
        print('waiting for next event')
        (readable, writable, exceptional) = select.select(self.inputs, self.outputs, self.inputs, self.timeout)
        if (not (readable or writable or exceptional)):
            print('Time out ! ')
            break
        for ser in readable:
            if (ser is self.server):
                (connection, client_address) = ser.accept()
                print('connection from ', client_address)
                connection.setblocking(0)
                self.inputs.append(connection)
                self.message_queues[connection] = queue.Queue()
            else:
                data = ser.recv(1024)
                if data:
                    print('收到数据 ', data.decode(), '\n来自:', ser.getpeername())
                    self.message_queues[ser].put(data)
                    if (ser not in self.outputs):
                        self.outputs.append(ser)
                else:
                    print('closing', client_address)
                    if (ser in self.outputs):
                        self.outputs.remove(ser)
                    self.inputs.remove(ser)
                    ser.close()
                    del self.message_queues[ser]
        for ser in writable:
            try:
                next_msg = self.message_queues[ser].get_nowait()
            except queue.Empty:
                print(ser.getpeername(), 'queue empty')
                self.outputs.remove(ser)
            else:
                print('发送数据 ', str((response + next_msg.decode())), ' to ', ser.getpeername(), '\n')
                ser.send((response.encode() + next_msg))
        for ser in exceptional:
            print(' exception condition on ', ser.getpeername())
            self.inputs.remove(ser)
            if (ser in self.outputs):
                self.outputs.remove(ser)
            ser.close()
            del self.message_queues[ser]