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

scrcpy to remote server doesn't error, but doesn't work either #3300

Closed
2 tasks done
mark2185 opened this issue May 25, 2022 · 7 comments
Closed
2 tasks done

scrcpy to remote server doesn't error, but doesn't work either #3300

mark2185 opened this issue May 25, 2022 · 7 comments

Comments

@mark2185
Copy link

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

Environment

  • OS: host: archlinux, remote: amazon linux 2 (docker)
  • scrcpy version: 1.23
  • installation method: pacman
  • device model: Samsung galaxy S21 ultra (I tried galaxy S5 as well)
  • Android version: 12

Describe the bug
I'm not even sure if I'm holding it right, I couldn't figure it out from the docs.

I have an adb on a remote server I can connect to with adb -H <ip> -P <port>, and I connect to it with scrcpy, but I get no screen, no errors, and I don't know how to debug it.

The server was started with:

$> adb -a -P 5038 nodaemon server start

And I try connecting to it with:

 $> ADB_SERVER_SOCKET=tcp:172.24.20.11:32323 scrcpy --tunnel-host=172.24.20.11 --tunnel-port=32323 -b2M -m800 --max-fps 15
scrcpy 1.23 <https://github.com/Genymobile/scrcpy>
INFO: Tunnel host/port is set, --force-adb-forward automatically enabled.
/usr/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 191.3 MB/s (41123 bytes in 0.000s)
[server] INFO: Device: samsung SM-G998U1 (Android 12)

I don't have scrcpy installed on the remote server, only on the local host, and the port 32323 is forwarded and mapped to 5038 on which adb is running (and as I said, adb -H <ip> -P <port> works)

What more can I provide?

@rom1v
Copy link
Collaborator

rom1v commented May 25, 2022

You start the server on port 5038:

$> adb -a -P 5038 nodaemon server start

But connect on port 32323:

ADB_SERVER_SOCKET=tcp:172.24.20.11:32323

Is there a port redirection from 32323 to 5038 somewhere?

I think you'd need something like:

ADB_SERVER_SOCKET=tcp:172.24.20.11:5038 scrcpy --tunnel-host=172.24.20.11

See https://github.com/Genymobile/scrcpy#tunnels

@mark2185
Copy link
Author

mark2185 commented May 25, 2022

Is there a port redirection from 32323 to 5038 somewhere?

Yes, the adb is in a docker container which has the port 32323 mapped to 5038, from the original post:

and the port 32323 is forwarded and mapped to 5038 on which adb is running

See https://github.com/Genymobile/scrcpy#tunnels

I tried all of the combinations, setting ADB_SERVER_SOCKET to use 32323, but --tunnel-host=40000 which was also mapped to 5038, but to no avail. Are the port in ADB_SERVER_SOCKET and --tunnel-port supposed to be the same port, the one where adb is listening?

@mark2185
Copy link
Author

Do note that scrcpy connects, and recognizes the phone correctly (based on its output), the only thing that is missing is the screen.

@rom1v
Copy link
Collaborator

rom1v commented May 25, 2022

There are several connections involved.

First, scrcpy want to connect to your adb server, accessible at 172.24.20.11:32323 (which points to port 5038 on the remote). Once it is connected, it can push the server and execute it (so it lists the phone model, etc). This one works apparently.

Then this server starts listening on an abstract unix socket scrcpy to transmit video/controls. This is what does not work for you.

This socket is accessible on the remote (where your adb server runs) on port 27183 (by default, you can change with --port). But scrcpy does not run on the remote, it runs locally, so you must configure a redirection between a local port (say 27183 too) and the remote port (27183) in your docker. You could pass --port=27183 --tunnel-port=27183 to scrcpy just to be sure (or use different numbers).

Refs #2801 #2807.

@mark2185
Copy link
Author

There are several connections involved.

First, scrcpy want to connect to your adb server, accessible at 172.24.20.11:32323 (which points to port 5038 on the remote). Once it is connected, it can push the server and execute it (so it lists the phone model, etc). This one works apparently.

Then this server starts listening on an abstract unix socket scrcpy to transmit video/controls. This is what does not work for you.

This socket is accessible on the remote (where your adb server runs) on port 27183 (by default, you can change with --port). But scrcpy does not run on the remote, it runs locally, so you must configure a redirection between a local port (say 27183 too) and the remote port (27183) in your docker. You could pass --port=27183 --tunnel-port=27183 to scrcpy just to be sure (or use different numbers).

Refs #2801 #2807.

That does it, I forwarded port 27183 to 27183 for the docker and ran scrcpy with --port=27183 --tunnel-port=27183 locally and it works, thanks!

Just trying to understand the whole setup - the scrcpy server on the android device is communicating with its "host" via port 27183 (which is defined by --port), and my local client is trying to communicate with it through the tunnel, but through the port --tunnel-port?

So if I make them different, I'd have to map port tunnel-port from the docker's host to port within the container? I.e. -p <tunnel-port>:<port>?

I tried it out and it works, but I am not sure I understand why. A tunnel port:localhost:tunnel-port remote-server.com is created?

@rom1v
Copy link
Collaborator

rom1v commented May 25, 2022

There is a first tunnel between the adb server and the device (tcp:27183 by default -> "localabstract:scrcpy"), then your docker tunnel (tcp:XXXX -> tcp:27183).

Scrcpy must connect to XXXX to access the device socket (through the 2 tunnels): even if it executes adb forward tcp:27183 localabstract:scrcpy (so that it thinks that it must use 27183), the port it must connect to is in fact XXXX (and the docker tunnel XXXX->27183 must exist).

@mark2185
Copy link
Author

That clears it up, thanks!

Triple thanks - for the quick response, for a great explanation, and for a great tool! :)

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