def send_message(self, user, message): self.msg.compose('msg', msg_to=user, msg_from=self.user, msg=message) if self.msg.send_message(self.socket): response = self.rsp.read_response(self.socket) if user.startswith('#'): msg = JimMessage() msg.read_message(self.socket) return response return None
def handle(self): chatroom.adduser(self.request) server_log.info('connected {} clients'.format(chatroom.num_users())) while True: msg = JimMessage() rsp = JimResponse() try: data = msg.read_message(self.request) server_log.info('Received from client: {}'.format(data)) self.handle_input(data).send_response(self.request) if data['action'] == 'msg': if data['to'].startswith('#'): server_log.info( 'Sending message to chat {}'.format(data)) chatroom.send_to_all(msg) except: break del msg del rsp server_log.info('client disconnected') chatroom.deluser(self.request)
def reading_loop(self): msg = JimMessage() while True: data = msg.read_message(self.socket) print(data)