scrcpy/doc/tunnels.md
Romain Vimont f12590ed08 Rework README and documentation
The README.md page is HUGE. Split it up.

Also document audio forwarding and improve installation instructions for
each platform and user documentation.

PR #3774 <https://github.com/Genymobile/scrcpy/pull/3774>
2023-03-12 02:04:58 +01:00

2.5 KiB

Tunnels

Scrcpy is designed to mirror local Android devices. Tunnels allow to connect to a remote device (e.g. over the Internet).

To connect to a remote device, it is possible to connect a local adb client to a remote adb server (provided they use the same version of the adb protocol).

Remote ADB server

To connect to a remote adb server, make the server listen on all interfaces:

adb kill-server
adb -a nodaemon server start
# keep this open

Warning: all communications between clients and the adb server are unencrypted.

Suppose that this server is accessible at 192.168.1.2. Then, from another terminal, run scrcpy:

# in bash
export ADB_SERVER_SOCKET=tcp:192.168.1.2:5037
scrcpy --tunnel-host=192.168.1.2
:: in cmd
set ADB_SERVER_SOCKET=tcp:192.168.1.2:5037
scrcpy --tunnel-host=192.168.1.2
# in PowerShell
$env:ADB_SERVER_SOCKET = 'tcp:192.168.1.2:5037'
scrcpy --tunnel-host=192.168.1.2

By default, scrcpy uses the local port used for adb forward tunnel establishment (typically 27183, see --port). It is also possible to force a different tunnel port (it may be useful in more complex situations, when more redirections are involved):

scrcpy --tunnel-port=1234

SSH tunnel

To communicate with a remote adb server securely, it is preferable to use an SSH tunnel.

First, make sure the adb server is running on the remote computer:

adb start-server

Then, establish an SSH tunnel:

# local  5038 --> remote  5037
# local 27183 <-- remote 27183
ssh -CN -L5038:localhost:5037 -R27183:localhost:27183 your_remote_computer
# keep this open

From another terminal, run scrcpy:

# in bash
export ADB_SERVER_SOCKET=tcp:localhost:5038
scrcpy
:: in cmd
set ADB_SERVER_SOCKET=tcp:localhost:5038
scrcpy
# in PowerShell
$env:ADB_SERVER_SOCKET = 'tcp:localhost:5038'
scrcpy

To avoid enabling remote port forwarding, you could force a forward connection instead (notice the -L instead of -R):

# local  5038 --> remote  5037
# local 27183 --> remote 27183
ssh -CN -L5038:localhost:5037 -L27183:localhost:27183 your_remote_computer
# keep this open

From another terminal, run scrcpy:

# in bash
export ADB_SERVER_SOCKET=tcp:localhost:5038
scrcpy --force-adb-forward
:: in cmd
set ADB_SERVER_SOCKET=tcp:localhost:5038
scrcpy --force-adb-forward
# in PowerShell
$env:ADB_SERVER_SOCKET = 'tcp:localhost:5038'
scrcpy --force-adb-forward