Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"connect: No error" error with remote ADB server #1939

Open
2 tasks done
JMLX42 opened this issue Nov 27, 2020 · 9 comments
Open
2 tasks done

"connect: No error" error with remote ADB server #1939

JMLX42 opened this issue Nov 27, 2020 · 9 comments

Comments

@JMLX42
Copy link

JMLX42 commented Nov 27, 2020

  • I have read the FAQ.
  • I have searched in existing issues.

Environment

  • OS: Windows 10
  • scrcpy version: 1.16
  • installation method: unzip the Windows release
  • device model: SM-T819
  • Android version: 7

I want to access the Android device via scrcpy via a Wireguard VPN.
Here is a the setup:

  • A: Samsung Tab S2
    • Wireguard installed and working
    • has IP 10.1.0.12 on the VPN
    • can be pinged via the VPN
    • can be connected to via scrpy from B
  • B: a Windows 10 PC
    • connected to the VPN
    • Windows firewall disabled
    • IP on the VPN is 10.1.0.6
    • on one terminal running adb server with adb nodaemon server
    • on another terminal
      • running scrcpy -s 10.1.0.12:5555 works as expected
      • setting $env:ADB_SERVER_SOCKET=tcp:10.1.0.6:5037 then running scrcpy -s 10.1.0.12:5555 also works as expected
  • C: another Windows 10 PC
    • connected to the VPN
    • Windows firewall disabled
    • VPN IP is 10.1.0.2
    • setting $env:ADB_SERVER_SOCKET=tcp:10.1.0.6:5037 then running .\adb.exe -H 10.1.0.6 devices -l returns the device list
.\adb.exe -a -H 10.1.0.6 devices -l
List of devices attached
386c9358               device product:gts210veltexx model:SM_T819 device:gts210velte transport_id:5
10.1.0.12:5555         device product:gts210veltexx model:SM_T819 device:gts210velte transport_id:4

but setting $env:ADB_SERVER_SOCKET=tcp:10.1.0.6:5037 then running scrcpy -s 10.1.0.12:5555 does not works as expected:

.\scrcpy.exe --force-adb-forward -s 10.1.0.12:5555 -b 2M
INFO: scrcpy 1.16 <https://github.com/Genymobile/scrcpy>
C:\Users\jeanm\Downloads\scrcpy-win64-v1.16\scrcpy-server: 1 file pushed, 0 skipped. 36.3 MB/s (33622 bytes in 0.001s)
[server] INFO: Device: samsung SM-T819 (Android 7.0)
connect: No error
connect: No error
connect: No error
connect: No error
connect: No error
connect: No error

the connect: No error line repeats endlessly.

.\scrcpy.exe -s "10.1.0.12:5555"
INFO: scrcpy 1.16 <https://github.com/Genymobile/scrcpy>
C:\Users\jeanm\Downloads\scrcpy-win64-v1.16\scrcpy-server: 1 file pushed, 0 skipped. 22.1 MB/s (33622 bytes in 0.001s)
adb.exe: error: more than one device/emulator
ERROR: "adb reverse" returned with value 1
WARN: 'adb reverse' failed, fallback to 'adb forward'
27183
[server] INFO: Device: samsung SM-T819 (Android 7.0)
connect: No such file or directory
connect: No such file or directory
connect: No such file or directory
connect: No such file or directory

the connect: No such file or directory line repeats endlessly.

Yet .\adb.exe -a -H 10.1.0.6 -s 10.1.0.12:5555 shell works as expected. So I suspect the remote adb server is working and available.

Please advise.

@rom1v
Copy link
Collaborator

rom1v commented Nov 28, 2020

connect: No error

This call fails:

if (connect(sock, (SOCKADDR *) &sin, sizeof(sin)) == SOCKET_ERROR) {

(and No error because it's windows and it does not give the error.)

What happens if you forward a port manually:

adb -s 10.1.0.12:5555 forward tcp:1234 tcp:1234

Then connect to it, for example via netcat:

netcat localhost 1234

Does it return immediately, or does it print an error message?

@JMLX42
Copy link
Author

JMLX42 commented Mar 31, 2021

Does it return immediately, or does it print an error message?

I don't have netcat on Windows.

I've tried a new setup as follows:

  • A: Samsung Tab S2
    • Wireguard installed and working
    • has IP 10.1.0.12 on the VPN
    • can be pinged via the VPN
    • can be connected to via scrpy from B
  • B: a Ubuntu 20.04 PC
    • connected to the VPN
    • firewall disabled
    • ADB running in a Docker container with ports 5037 and 27183 are mapped
    • IP on the VPN is 10.1.0.15
  • C: a Windows 10 PC
    • connected to the VPN
    • Windows firewall disabled
    • VPN IP is 10.1.0.2
    • setting $env:ADB_SERVER_SOCKET="tcp:10.1.0.6:5037" then running .\adb.exe devices -l returns the device list

But scrcpy does not work:

.\scrcpy.exe -V debug
INFO: scrcpy 1.17 <https://github.com/Genymobile/scrcpy>
DEBUG: Using server (portable): C:\scrcpy-win64-v1.17\scrcpy-server
C:\scrcpy-win64-v1.17\scrcpy-server: 1 file pushed, 0 skipped. 46.8 MB/s (34930 bytes in 0.001s)
DEBUG: Screensaver enabled
[server] INFO: Device: samsung SM-T819 (Android 7.0)
[server] DEBUG: Controller stopped
[server] DEBUG: Using encoder: 'OMX.qcom.video.encoder.avc'
[server] DEBUG: Screen streaming stopped
[server] DEBUG: Device message sender stopped
DEBUG: Server terminated

In the remote ADB server logs:

adb E 03-31 15:29:55     1     1 services.cpp:83] failed to connect to socket 'tcp:27183': Address not available

I have ad this comment already. But I was hoping being on a VPN - so basically the same network - would avoid using the SSH tunnel.

@JMLX42
Copy link
Author

JMLX42 commented Mar 31, 2021

Actually, the problem is a bit different if I use the SSH tunnel:

ssh -CN -L5037:localhost:5037 -R27183:localhost:27183 my.remote.vpn.host.com
.\scrcpy -V debug
.\scrcpy.exe -V debug
INFO: scrcpy 1.17 <https://github.com/Genymobile/scrcpy>
DEBUG: Using server (portable): C:\scrcpy-win64-v1.17\scrcpy-server
C:\scrcpy-win64-v1.17\scrcpy-server: 1 file pushed, 0 skipped. 55.3 MB/s (34930 bytes in 0.001s)
DEBUG: Screensaver enabled
[server] INFO: Device: samsung SM-T819 (Android 7.0)
[server] DEBUG: Using encoder: 'OMX.qcom.video.encoder.avc'

The device screen does light up. Then the terminal hangs there. Then after a few seconds:

[server] DEBUG: Controller stopped

And the terminal hangs again.

The ADB server logs show nothing at all.

The ADB client works as expected:

.\adb.exe devices -l
List of devices attached
386c9358               device usb:3-11 product:gts210veltexx model:SM_T819 device:gts210velte transport_id:3

Killing the SSH tunel does stop scrcpy:

DEBUG: Server terminated
* daemon not running; starting now at tcp:5037
* daemon started successfully
adb.exe: error: no devices/emulators found
ERROR: "adb reverse --remove" returned with value 1

which would indicate the SSH tunnel is indeed used.

@JMLX42
Copy link
Author

JMLX42 commented Mar 31, 2021

The following works:

ssh -CN -L5037:localhost:5037 -L27183:localhost:27183 my.remote.vpn.host.com
.\scrcpy.exe -V debug --force-adb-forward

But I'm still surprised I need to use an SSH tunnel when:

  • The Android device is connected directly using USB to the remove ADB server.
  • The Android device, the machine running scrcpy and the ADB server are all on the same (VPN) network.

@JMLX42
Copy link
Author

JMLX42 commented Mar 31, 2021

The following also works:

ssh -CN -L27183:localhost:27183 my.remote.vpn.host.com
$env:ADB_SERVER_SOCKET="tcp:my.remote.vpn.host.com:5037"
.\scrcpy.exe -V debug --force-adb-forward
INFO: scrcpy 1.17 <https://github.com/Genymobile/scrcpy>
DEBUG: Using server (portable): C:\scrcpy-win64-v1.17\scrcpy-server
C:\scrcpy-win64-v1.17\scrcpy-server: 1 file pushed, 0 skipped. 60.4 MB/s (34930 bytes in 0.001s)
27183
DEBUG: Screensaver enabled
DEBUG: Remaining connection attempts: 100
DEBUG: Remaining connection attempts: 99
DEBUG: Remaining connection attempts: 98
DEBUG: Remaining connection attempts: 97
DEBUG: Remaining connection attempts: 96
DEBUG: Remaining connection attempts: 95
[server] INFO: Device: samsung SM-T819 (Android 7.0)
DEBUG: Remaining connection attempts: 94
DEBUG: Remaining connection attempts: 93
DEBUG: Starting stream thread
DEBUG: Starting controller thread
DEBUG: Starting receiver thread
[server] DEBUG: Using encoder: 'OMX.qcom.video.encoder.avc'
INFO: Renderer: direct3d
DEBUG: Trilinear filtering disabled (not an OpenGL renderer)
INFO: Initial texture: 1536x2048

@JMLX42
Copy link
Author

JMLX42 commented Mar 31, 2021

So my conclusion is that the scrcpy client expects to connect to localhost:27183 (when --force-adb-forward is used).

Yet I don't see any actual ADB reverse/forward from the ADB client:

PS C:\scrcpy-win64-v1.17> $env:ADB_SERVER_SOCKET="my.remote.vpn.host.com:5037"
PS C:\scrcpy-win64-v1.17> .\adb.exe reverse --list

PS C:\scrcpy-win64-v1.17> .\adb.exe forward --list

Wouldn't it be possible to specify another host?

@JMLX42
Copy link
Author

JMLX42 commented Mar 31, 2021

Wouldn't it be possible to specify another host?

I guess the work being done here would match that requirement:

#1159

@JMLX42
Copy link
Author

JMLX42 commented Mar 31, 2021

After further investigation, hen running .\scrcpy.exe --force-adb-forward, then I get:

.\adb.exe forward --list
386c9358 tcp:27183 localabstract:scrcpy

Which means scrcpy does setup an adb forward. But somehow, because of adb limitations, that forwards the port to localhost and there is no way to specify the host. Hence the need for an SSH tunnel to route localhost:27183 to the remote ADB server.

So it would seem it is an adb limitation and nothing can be done. Do you confirm @rom1v ?

@JMLX42
Copy link
Author

JMLX42 commented Mar 31, 2021

Actually, this line of code:

socket_t socket = net_connect(IPV4_LOCALHOST, port);

suggests that scrcpy always connects to localhost. @rom1v could we add a --device-host option to specify the host instead of IPV4_LOCALHOST?

So in the case of a device on the same VPN as the machine running scrcpy, it would connect directly to the device using it's VPN IP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants