Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
111.56k stars 10.69k forks source link

Remote Access through vpn server-> adb device [offline]? #3848

Open alan0048 opened 1 year ago

alan0048 commented 1 year ago

Environment

Using the command line "scrcpy -m800 -b2M --no-audio" I am able to mirror my Nvidia Shield Pro through my computer while I'm on the same LAN. When away from home, I can usually connect to my local lan through a Wireguard Server. Hence, I thought I'd be able to connect as usual but my adb device only shows offline?

Why isn't it working? Is there a way to get around that? Computer A --> Internet ---> Wireguard Server ---> Router (Computer B) ---> Nvidia Shield Pro [offline]

rom1v commented 1 year ago

You can adb connect only one adb client per device.

You might be interested in this page: https://github.com/Genymobile/scrcpy/blob/master/doc/tunnels.md

alan0048 commented 1 year ago

I'm afraid I didn't get that working. I will try again soon, but I'm having a hard time following what to do.

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

From another terminal on the same computer? Or a different?

edit: Had to revoke all access on my Shield and start over again. List of devices had dissapeared but is now solved.

rom1v commented 1 year ago

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

From another terminal on the same computer? Or a different?

On the remote computer (where your Android device is plugged/connected), you execute:

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

On your local computer (where you want to run scrcpy), you execute:

# in bash
export ADB_SERVER_SOCKET=tcp:192.168.1.2:5037
scrcpy --tunnel-host=192.168.1.2

192.168.1.2 is the address of the remote computer as seen from the local computer.

alan0048 commented 1 year ago

Does this mean that the remote computer has to be turned on at all time in order to access the Android device remotley? I thought you could connect to the Android device solemnly from an outside network, that's what I was hoping to achieve.

Scenario 1: Computer A --> (Router A / Local LAN) --> Nvidia Shield / 192.168.10.XXX

Scenario 2: Computer A --> (Router B / Internet) --> VPN Adress --> (Router A / Local LAN) --> Nvidia Shield / 192.168.10.XXX

Can this be achieved?

rom1v commented 1 year ago

Does this mean that the remote computer has to be turned on at all time in order to access the Android device remotley?

Yes, you communicate with the device via the computer where it is connected, not directly.

michaelk-realityi commented 12 months ago

@alan0048 I have found that only one PC can have an active adb connection to the same device. If your remote pc is the 2nd device connecting it might connect but show offline. Before leaving the house make sure to run 'adb disconnect 192.168.10.XXX' (this will disconnect the one device) on the computer that is currently connected to your Nvidia Shield. IF your laptop is the one connected at your house and then attempting to connect via VPN you may need to reboot the Nvidia Shield to stop the adb session on the Nvidia Shield.

I was able to just achieve the reverse of your Scenario 2 with an Android 7 device in my office. It VPN'ed into the office and I connected to it. Then a coworker VPN'ed into the office and connected to the Android 7 device across both VPNs. However I had to 'adb disconnect' from it before my coworker was able connect.

My Scenario 1: Remote Android A --> (Router B/ Internet) --> VPN Address --> (Router A / Local LAN ) <-- Computer A

My Scenario 2: Remote Android A --> (Router B/ Internet) --> VPN Address --> (Router A / Local LAN ) <-- VPN Address <-- (Router C/ Internet) Remote Computer 2

rom1v commented 12 months ago

I have found that only one PC can have an active adb connection to the same device.

Yes, this is an adb server limitation.