def on_open(self): print('Connection established, ') print('but messages are not encrypted yet.') print('Use /help for command list. /exit to leave server') handshake = json.dumps(vars(Message('Handshake', self.crypto.my_public.n))) self.send(handshake, False) thread.start_new_thread(self.chatting, ())
def chatting(self): # Function to input text while True: message = input() if message[0] == '/': # Call the commands func if message contains '/' self.commands(message) continue message = Message('Message', {'Name': self.name, 'Message': message}) self.send(json.dumps(vars(message)))
def handshake(self, key): if self.crypto.partner_public is None: self.crypto.save_partner_public(key) handshake = json.dumps( vars(Message('Handshake', self.crypto.my_public.n))) self.send(handshake, False) puts( colored.magenta( 'Partner has been connected. All messages are now encrypted!' ))
async def unregister(self, websocket): print('Client disconnected') self.clients.remove(websocket) message = json.dumps(vars(Message('System', 1))) await self.send_to_clients(message=message)