Skip to content

Wire Protocol Reference

The Extraspace wire protocol is shared between crates/xs-proto (Rust) and Protocol.kt (Android/Kotlin). The current protocol version is PROTOCOL_VERSION = 2.

Ports sit just above scrcpy (27183) and are either forwarded over adb (USB) or connected directly over LAN TCP:

Constant Port Transport Purpose
ports::CONTROL 27183 TCP JSON control messages & binary multi-touch events
ports::VIDEO 27184 TCP Host → tablet H.264 desktop video stream
ports::CAMERA 27185 TCP Tablet → host H.264 webcam stream
ports::POWER 27186 TCP Bidirectional lock / unlock / suspend / wake sync
ports::DISCOVERY 27187 UDP LAN auto-discovery broadcast (magic payload: XSPA_DISCOVER)

Every frame on every channel starts with a fixed 20-byte little-endian header. Payloads above 16 MiB (MAX_PAYLOAD = 16 * 1024 * 1024) are rejected early:

Offset Size Field Type Description
0..4 4 magic u32 0x4150_5358 (ASCII "XSPA" on the wire)
4 1 channel u8 Logical Channel enum
5 1 kind u8 Message kind (interpreted per-channel)
6..8 2 flags u16 Flags bitfield
8..12 4 len u32 Payload length in bytes
12..20 8 pts_us u64 Presentation timestamp in microseconds
Value Name Description
0 Control JSON-encoded control messages
1 Touch Fixed 21-byte binary touch events
2 VideoDown Downlink H.264 desktop frames
3 CameraUp Uplink H.264 camera frames
4 Power Independent power / lock / sleep lifecycle messages (JSON)
Flag Value Description
KEYFRAME 1 << 0 Payload is an IDR keyframe
CODEC_CONFIG 1 << 1 Payload is codec configuration (SPS/PPS), not a displayable frame
INTRA_REFRESH 1 << 2 Frame carries rolling intra-refresh macroblocks
DISCONTINUITY 1 << 3 One or more preceding frames were dropped before transmission

Payloads on Channel::Control are JSON-encoded for readability in logs:

kind Name Direction Description
0 Hello Tablet → Host Initial handshake: protocol version, device name, Android release, native panel resolution, DPI, refresh rate, and available cameras
1 VideoConfig Host → Tablet Announces display stream width, height, framerate, bitrate, and codec ("h264")
2 Stats Tablet → Host Periodic decode queue depth, decoded/dropped frame counts, and render timestamps driving adaptive bitrate
3 CameraControl Host → Tablet Starts/stops camera capture with target camera ID, resolution, framerate, and bitrate
4 Ping Either Liveness & RTT probe carrying pts_us
5 Pong Either Echoes Ping’s pts_us
6 Error Either Fatal error notification before closing the connection
7 Rfi Tablet → Host Reference Frame Invalidation — pts_us carries the last good PTS so the host emits an urgent IDR / intra refresh
8 TouchControl Host → Tablet Enables or disables touch forwarding from the tablet

Touch events arrive at up to 120 Hz per finger, so they use a fixed 21-byte little-endian layout instead of JSON:

Offset Size Field Type Description
0 1 action u8 0 = Down, 1 = Motion, 2 = Up
1..5 4 slot u32 Multi-touch pointer slot ID
5..13 8 x f64 Stream X coordinate (sub-pixel precision)
13..21 8 y f64 Stream Y coordinate (sub-pixel precision)

Carried over port 27186 with a PowerEvent JSON payload (unix_time_ms, monotonic_us, locked, sleeping, allow_sleep, reason):

kind Name Description
0 StateSync Initial or periodic full-state + wall-clock snapshot
1 HostLocked Host screen locked (gst::State::Paused, virtual monitor retained)
2 HostUnlocked Host screen unlocked (gst::State::Playing resumed)
3 HostSuspend Host entering suspend; tablet sleeps synchronously
4 HostResume Host resumed from suspend
5 TabletSleep Tablet screen turned off / standby
6 TabletWake Tablet screen turned on
7 TabletLocked Tablet keyguard engaged
8 TabletUnlocked Tablet keyguard dismissed (ACTION_USER_PRESENT)