This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import asyncio | |
| import websockets | |
| async def hello(): | |
| try: | |
| async with websockets.connect('ws://localhost:8765') as websocket: | |
| # send a message to the server | |
| await websocket.send('Hello, server!') | |
| # receive a message from the server | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from cryptography.fernet import Fernet | |
| # generate a secret key | |
| #key = Fernet.generate_key() | |
| # get the key from the user | |
| key_input = input("Enter the key: ") | |
| # convert the key input to bytes | |
| key = bytes(key_input, "utf-8") | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # WebSocket server implementation in Python3 using the websockets library | |
| import asyncio | |
| import websockets | |
| async def server(websocket, path): | |
| print(f"New client connected: {websocket.remote_address}") | |
| async for message in websocket: | |
| print(f"Received message: {message}") | |
| response = f"Server received your message: {message}" | |
| await websocket.send(response) |