How divslayer/anydeskapp works
Project Type and Purpose
• This is a lightweight Python-based client-server remote desktop application (in the style of AnyDesk).
• It comprises two runtime roles:
a) Server (remote_machine.py): Captures the desktop, encodes frames, streams them over a secure WebSocket, and listens for incoming mouse/keyboard events.
b) Client/Viewer (viewer.py): Connects to the server’s WebSocket, decodes and displays video frames, and sends user input events back.
File Structure Analysis
• Top-level scripts:
• gui.py – Tkinter GUI that lets you choose “Be Remote Machine” or “Connect to Remote.”
• remote_machine.py – The server process.
• viewer.py – The client process.
• get_local_ip.py – Utility to discover local IP addresses.
• test.py – (Presumably simple smoke tests or examples.)
• SSL certificates: cert.pem, key.pem (for TLS).
• requirements.txt – Lists dependencies (websockets, mss, OpenCV, pyautogui, etc.).
Architecture Insights from README
• Uses a secure WebSocket (wss://) connection for bidirectional comms.
• Video frames are JPEG-encoded via OpenCV and sent over the socket.
• Input events (mouse/keyboard) are captured client-side (pyautogui) and injected server-side.
• GUI is Tkinter, offering a simple launcher.
Main Components
a. Launcher GUI (gui.py)
• Branches into either Server or Client mode.
b. Server Process
• Screen Capture Module (mss or pyautogui for screenshots)
• Encoder Module (OpenCV JPEG encoder)
• WebSocket Server (websockets + ssl.wrap_socket)
• Input Handler (pyautogui to inject events)
c. Client/Viewer Process
• WebSocket Client (connects to wss://server:port)
• Decoder Module (OpenCV JPEG decoder)
• Display Window (OpenCV imshow or Tkinter canvas)
• Input Capturer (captures local mouse/keyboard events)
d. SSL/TLS Layer
• Self-signed certificates (cert.pem, key.pem) securing the WebSocket channel.
e. Network
Relationships & Interactions
• The Launcher GUI spins up either the Server or the Client.
• In Server Mode:
• → Encode → WebSocket Send → Network
• WebSocket Receive → Input Handler → Inject into OS
• In Client Mode:
• WebSocket Receive → Decode → Render → Display Window
• Input Capture → WebSocket Send → Network
Architectural Patterns & Principles
• Client-Server Architecture: Clear separation of responsibilities.
• Modular Design: Distinct modules for capture, encode/decode, transport, and input handling.
• Secure Communication: All network traffic runs over TLS.
• Event-Driven I/O: WebSocket callbacks drive video and input pipelines.
Technologies & Frameworks
• Python 3.7+
• Tkinter (GUI launcher)
• websockets (asyncio-based WebSocket server/client)
• ssl (native Python TLS)
• mss or pyautogui (screen capture)
• OpenCV (cv2) for JPEG encoding/decoding
• pyautogui for input injection