Пример #1
0
 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, ())
Пример #2
0
 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)))
Пример #3
0
 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!'
             ))
Пример #4
0
 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)