This page provides a top-level overview of the backend services that run on the controlled (host) side of a RustDesk session. These services are responsible for capturing and transmitting screen video, audio, and clipboard content, and for executing input events injected by the remote controller. They also include the IPC layer used for inter-process coordination.
This page describes the overall architecture and how services are structured. Detailed documentation for each service is in the child pages:
For information about how connections are established and authenticated, see Connection Management. For the server process model and how services are started, see Service Architecture.
All core services are instantiated and managed by the Server struct, defined in src/server.rs. When the server process starts, new() constructs a Server and registers every global service into its services map.
Server struct src/server.rs102-109
Server {
connections: ConnMap, // active connections keyed by i32 ID
services: HashMap<String, Box<dyn Service>>,
id_count: i32,
}
Services are registered at startup via add_service() src/server.rs111-159:
| Service name constant | Module | Platform |
|---|---|---|
audio_service::NAME | src/server/audio_service.rs | All |
display_service | src/server/display_service.rs | Non-iOS |
clipboard_service::NAME | src/server/clipboard_service.rs | Non-iOS |
clipboard_service::FILE_NAME | src/server/clipboard_service.rs | Unix file-copy-paste feature |
input_service::NAME_CURSOR | src/server/input_service.rs | Non-Android/iOS, no embedded cursor |
input_service::NAME_POS | src/server/input_service.rs | Non-Android/iOS, no embedded cursor |
input_service::NAME_WINDOW_FOCUS | src/server/input_service.rs | Non-Android/iOS (X11 only on Linux) |
printer_service::NAME | src/server/printer_service.rs | Windows + Flutter only |
Terminal service is created per connection, not globally src/server.rs157
Sources: src/server.rs80-159
Services broadcast data to all interested connections through a subscriber model. Each connection is represented by a lightweight ConnInner value that implements the Subscriber trait.
Service-to-connection data flow diagram
ConnInner::send() src/server/connection.rs319-339 routes messages: VideoFrame and SwitchDisplay messages go through tx_video; everything else goes through tx. This separates video delivery from control messages to avoid head-of-line blocking.
A connection subscribes or unsubscribes from a service when permissions change, e.g., audio permission toggled src/server/connection.rs620-637:
Sources: src/server/connection.rs125-339 src/server.rs102-159
Each accepted TCP connection spawns a Connection::start() task src/server/connection.rs350-482 The Connection struct tracks the full state of one remote session, including:
| Field | Purpose |
|---|---|
keyboard, clipboard, audio, file, restart, recording, block_input | Per-connection feature permissions |
authorized | Whether login has been completed |
require_2fa | Pending 2FA challenge |
file_transfer, view_camera, terminal | Connection mode flags |
tx_to_cm / rx_from_cm | IPC channels to the Connection Manager process |
tx_input | Channel to the input handler thread |
audio_sender | Sender for local audio (voice call) |
Connection startup and service subscription diagram
Sources: src/server/connection.rs349-530 src/server/connection.rs207-305
The server process (--server), the main UI process, and the Connection Manager process (--cm) communicate through the Data enum serialized over named pipes (Windows) or Unix domain sockets. See IPC Communication for full details.
Key Data variants relevant to core services src/ipc.rs221-310:
| Variant | Direction | Purpose |
|---|---|---|
Data::Login{...} | server → CM | Notify CM of new connection with capabilities |
Data::Authorize | CM → server | CM approved the connection |
Data::Close | CM → server | CM requests session termination |
Data::SwitchPermission{name, enabled} | CM → server | Toggle keyboard/audio/clipboard/file/restart/recording/block_input |
Data::ChatMessage{text} | CM → server | Forward chat message to remote |
Data::FS(FS::...) | bidirectional | File system operations for file transfer |
Data::VoiceCallResponse(bool) | CM → server | Accept/reject voice call |
Data::PrivacyModeState(...) | server → CM | Privacy mode state changes |
Data::ClipboardFile(...) | CM → server | Clipboard file content from CM |
IPC data flow diagram
Sources: src/ipc.rs44-400 src/server/connection.rs368-376 src/server/connection.rs559-766
Input events (mouse, keyboard, pointer device) from the remote client are delivered inside Connection::on_message() and dispatched to a dedicated input handler thread via tx_input: std_mpsc::Sender<MessageInput> src/server/connection.rs253
The MessageInput enum src/server/connection.rs141-156 carries:
| Variant | Payload |
|---|---|
Mouse(InputMouse) | Mouse event with connection metadata |
Key((KeyEvent, bool)) | Key event with press flag |
Pointer((PointerDeviceEvent, i32)) | Pointer/stylus event |
BlockOn / BlockOff | Block all local input |
BlockOnPlugin(String) / BlockOffPlugin(String) | Block input via plugin |
The input handler thread is spawned in Connection::start() src/server/connection.rs530:
Sources: src/server/connection.rs141-156 src/server/connection.rs253 src/server/connection.rs529-530
A single Connection can operate in one of several modes, determined at login time:
| Mode | Field | Description |
|---|---|---|
| Default (remote control) | (default) | Full screen sharing + input injection |
| File transfer | file_transfer: Option<(String, bool)> | No video service; file protocol only |
| Port forward | port_forward_socket | TCP tunnel mode |
| View camera | view_camera: bool | Camera feed instead of desktop capture |
| Terminal | terminal: bool | Remote terminal session |
The AuthConnType enum src/server/connection.rs181-187 enumerates these:
Stream send timeout is adjusted per mode src/server/connection.rs521-527: file transfer and port forward use a longer timeout (SEND_TIMEOUT_OTHER = 120_000 ms) compared to video streaming (SEND_TIMEOUT_VIDEO = 12_000 ms).
Sources: src/server/connection.rs181-187 src/server/connection.rs215-220 src/server/connection.rs521-527
| File | Role |
|---|---|
src/server.rs | Server struct, service registry, TCP listener, accept_connection_ |
src/server/connection.rs | Connection, ConnInner, Subscriber, per-connection session logic |
src/server/audio_service.rs | Audio capture and streaming service |
src/server/video_service.rs | Video capture and encoding service |
src/server/display_service.rs | Display enumeration and change detection |
src/server/clipboard_service.rs | Clipboard monitoring and sync |
src/server/input_service.rs | Cursor, position, and window focus services |
src/server/terminal_service.rs | Per-connection terminal sessions |
src/server/printer_service.rs | Windows printer redirection (Flutter only) |
src/ipc.rs | Data enum, FS enum, IPC socket connect/listen functions |
src/server/service.rs | Service, GenericService, ServiceTmpl, Subscriber traits |
src/server/video_qos.rs | Quality-of-service and bitrate control for video |
Refresh this wiki
This wiki was recently refreshed. Please wait 2 days to refresh again.