RPC protocol and session flow
The RPC client is the boundary between the desktop app and a Transmission daemon. It turns app requests into JSON-RPC calls over HTTP, manages the daemon session, and returns torrent or session data to the UI. For the wider client role, see Transmission RPC integration; connection profiles and endpoint settings are covered in Daemon connection configuration.
Protocol contract
Transmission RPC uses a small JSON contract over HTTP POST. The client keeps this contract in one request path so that UI code can ask for a command or data without handling HTTP details itself.
Request and response messages
An RPC request names one method and can carry an arguments object. A response reports success or an error in result; successful calls can also return an arguments object. The client exposes either that arguments object or the full response when a caller needs to inspect the response shape, such as session statistics.
The client sends UTF-8 JSON to the configured RPC URL. It asks the server for gzip content and parses the response as JSON before it checks the result. A missing result, a non-object response, or a missing arguments object when one is required becomes an RPC error instead of application data.
References: rpc-spec.txt• L22-67 rpc.pas• L902-914 rpc.pas• L1067-1143
HTTP transport
The transport uses HTTP POST with the default path /transmission/rpc. The endpoint itself comes from the active connection profile, so the protocol page explains request behavior while Daemon connection configuration explains how the endpoint is chosen.
The shared HTTP session is protected while a request is sent and its response is read. A request can use the normal connection timeout or a call-specific timeout. This lets long operations such as a blocklist update or a torrent command stop without leaving the client waiting forever.
References: rpc.pas• L44-46 rpc.pas• L962-1005 rpc.pas• L1287-1316 rpc-spec.txt• L47-54
Session negotiation
The client must establish a valid Transmission session before it can present reliable daemon state. It learns the server capabilities from session-get, then uses that information to choose compatible fields and optional calls.
Session identifier exchange
Transmission protects most RPC endpoints with an X-Transmission-Session-Id value. The client sends the current value with each request. When the daemon rejects it with HTTP 409, the client takes the replacement value from the response headers and retries the same request.
The first background request is session-get. A successful reply marks the client as connected and records the daemon RPC version and version string. The client also checks free space in the download directory when the server supports the newer free-space method. A failed handshake leaves the connection unavailable and exposes the error through the client status.
References: rpc-spec.txt• L56-67 rpc.pas• L976-1015 rpc.pas• L452-504
Session refresh cycle
After negotiation, a background RPC thread owns the regular read cycle. It refreshes the torrent list and selected-torrent details on the normal interval. It refreshes session information less often, while an explicit user action can request an immediate refresh.
Refresh requests are grouped as torrent-list, detail, or session work. Generation values make a completed response conditional on the request still being current. This prevents a slow response for an old torrent selection or old detail tab from replacing newer UI state. The thread passes accepted results back through the UI thread rather than updating the forms from the network thread.
The flow has three broad stages:
flowchart LR
A[Connect] --> B[session-get]
B --> C[Record RPC version]
C --> D[Refresh torrent list]
C --> E[Refresh selected details]
C --> F[Refresh session state]
D --> G[Update UI]
E --> G
F --> G
References: rpc.pas• L266-345 rpc.pas• L1335-1457 main.pas• L3375-3381
Torrent data queries
Torrent data is read through torrent-get, which requires a list of requested fields and can limit the result to one or more torrent IDs. The client uses this same query shape for the main list and for the selected torrent's peer, file, tracker, and general views.
Field selection
The query layer combines the fields needed by a caller with optional fields selected by the current view or user preference. It removes fields that the negotiated RPC version does not support. On newer servers it can request table-form results and convert them into the object form expected by the rest of the app.
This keeps the data contract small for normal polling while allowing a full-information refresh after a change. It also lets the client request large or less stable data, such as piece data, less often than the core torrent state.
References: rpc.pas• L506-563 rpc.pas• L703-741 rpc.pas• L1161-1203 rpc-spec.txt• L127-145
Detail views
The selected torrent controls which detail query runs. The general view asks for status, dates, sizes, rates, limits, tracker state, and metadata. Other views ask for peers, files, or trackers, while the statistics view asks for session statistics.
Changing the active detail view marks detail work as pending. Changing files, location, or the selected torrent also invalidates related detail state so the next accepted response reflects the new remote state. A response for a torrent that is no longer selected is not allowed to overwrite the current detail view.
References: rpc.pas• L565-664 rpc.pas• L666-799 rpc.pas• L1359-1405 main.pas• L5205-5213
Command dispatch
User actions become RPC method calls at the UI-to-client boundary. The command path adds the selected torrent IDs and action-specific arguments, sends the request through the shared RPC client, then asks the refresh cycle to reconcile the UI with the daemon.
Torrent commands
The common torrent command path supports actions such as start, stop, verify, remove, queue movement, and reannounce. The same path can carry command-specific values for torrent settings. A successful command refreshes the visible torrent state; a removal or file-related change also invalidates selected detail data.
Commands that need a different response shape use the lower-level request path directly. Torrent intake uses torrent-add and reads either the new torrent or the duplicate torrent identity. Moving content uses torrent-set-location, while file priority and tracker changes use torrent-set.
References: main.pas• L7450-7490 main.pas• L7492-7531 main.pas• L2600-2649 main.pas• L2183-2205 rpc-spec.txt• L69-125 rpc-spec.txt• L356-441
Session and utility commands
Session settings use session-set and are followed by a session refresh. The UI also uses direct RPC calls for session-get, session-stats, free-space, port-test, and blocklist-update. These calls still use the same session identifier, result checks, status reporting, and timeout rules as torrent commands.
The command boundary therefore has one consistent outcome model: a successful write schedules new state from the daemon, while a failed response leaves the current state in place and reports the failure. This avoids treating a locally accepted form value as proof that Transmission applied it.
References: rpc.pas• L452-504 rpc.pas• L628-664 main.pas• L2759-2797 main.pas• L4380-4395 daemonoptions.pas• L147-168 rpc-spec.txt• L444-621
Change checklist
When these files or sections are changed, remember to consider these:
- When a Transmission field or method changes, update the protocol description and the query or dispatch path that creates it. Check both the request arguments and the code that reads the response.
- When a new RPC version adds or removes a field, review the version gates in
RequestInfoand every UI path that assumes the field exists. - When a write command changes remote torrent data, preserve the matching refresh or detail invalidation. Otherwise the UI can show an old list or selected-torrent view.
- When response handling changes, keep the distinction between a successful response with
argumentsand the full response used for result inspection. - When session or endpoint behavior changes, preserve the 409 session-ID retry and the configured RPC path. See Daemon connection configuration for the profile side of that contract.
- When background refresh behavior changes, preserve the handoff from the RPC thread to the UI thread and the checks that reject stale detail responses.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The daemon returns HTTP 409 with a new session ID. | The original call is rejected and no state is returned until the request is retried. | Replace the stored session header and retry the same request. |
| The daemon returns a non-200 HTTP result or invalid JSON. | The call produces a status error and the caller receives no usable RPC data. | Check transport status and validate the JSON result before consuming arguments. |
| A query sends a field that the negotiated RPC version does not support. | The torrent query can fail or return data that the client cannot interpret. | Remove unsupported fields and use the server's RPC version when building queries. |
| A slow detail response arrives after the user changes torrent or detail view. | Old data can replace the current selection. | Compare refresh and file generations with the current selection before applying detail data. |
| A write succeeds but no refresh is requested. | The daemon has new state while the list or detail pane still shows old state. | Schedule the matching list refresh and invalidate file details for file or location changes. |
The session statistics response lacks an arguments object. | Statistics become invalid and the UI reports an invalid server response. | Validate the response shape before passing it to the statistics view. |
Key files
| File | Why to read it |
|---|---|
rpc.pas | Defines the RPC boundary, session negotiation, background refresh cycle, torrent queries, response validation, and shared status state. |
| rpc-spec.txt | States the Transmission JSON-RPC message contract, session-ID rules, command families, response shapes, and version history. |
main.pas | Shows how user actions dispatch torrent and session commands and how successful writes trigger refresh or detail invalidation. |
addtorrent.pas | Shows how the add-torrent flow uses free-space before sending torrent data to the daemon. |
daemonoptions.pas | Shows a direct utility call through the shared client for testing the daemon's peer port. |
| docs/transmission-rpc-integration.md | Parent page for the client boundary and its relationship to application state and remote torrent operations. |
| docs/daemon-connection-configuration.md | Related page for connection profiles, endpoint selection, and authentication inputs used by the RPC boundary. |