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

Ability to specify adb and scrcpy server Host/Port's #2801

Closed
1 task done
clienthax opened this issue Nov 17, 2021 · 10 comments
Closed
1 task done

Ability to specify adb and scrcpy server Host/Port's #2801

clienthax opened this issue Nov 17, 2021 · 10 comments

Comments

@clienthax
Copy link

clienthax commented Nov 17, 2021

Is your feature request related to a problem? Please describe.
I require a way to specify connection host and port for both adb and the scrcpy connection (assuming forward connection).
I have multiple android devices connected to one parent host, and each usb is isolated inside a docker container (similar to https://github.com/sorccu/docker-adb)
This results in both the adb port and the scrcpy server port being exposed to different ports on the host system.

Describe the solution you'd like

  • Options for ADB Host/Port
  • Options for scrcpy server Host/Port

eg scrcpy --adbHost 192.168.1.50 --adbPort 9999 --scrcpyHost 192.168.1.50 --scrcpyPort 10000 --force-adb-forward

Describe alternatives you've considered

  • Using soccat to forward the ports locally from the remote and using --force-adb-forward, however this is fairly clunky.
  • Using the ADB env variable to specify the host and port via "ADB=adb -H host -P port", however this doesn't allow for scrcpy to function after installing the server.

Additional context
The client is not located on the same system as the devices, ssh forwarding is also not a good option due to these being isolated in their own containers.

@rom1v
Copy link
Collaborator

rom1v commented Nov 17, 2021

eg scrcpy --adbHost 192.168.1.50 --adbPort 9999 --scrcpyHost 192.168.1.50 --scrcpyPort 10000 --force-adb-forward

Isn't the host necessary the same for adb and scrcpy?

I would say yes, because the adb forward command executed by scrcpy opens a tunnel on the adb host, so the scrcpy host is necessarily the same, isn't it?

--scrcpyPort is basically the existing --port option IIUC.

Using the ADB env variable to specify the host and port via "ADB=adb -H host -P port"

Or even ADB_SERVER_SOCKET: #144 (comment)

The remaining problem is the hardcoded localhost I guess.

@clienthax
Copy link
Author

eg scrcpy --adbHost 192.168.1.50 --adbPort 9999 --scrcpyHost 192.168.1.50 --scrcpyPort 10000 --force-adb-forward

Isn't the host necessary the same for adb and scrcpy?

I would say yes, because the adb forward command executed by scrcpy opens a tunnel on the adb host, so the scrcpy host is necessarily the same, isn't it?

Yes the host would be the same, overlooked that :)

--scrcpyPort is basically the existing --port option IIUC.

Using the ADB env variable to specify the host and port via "ADB=adb -H host -P port"

Or even ADB_SERVER_SOCKET: #144 (comment)

Yep confirmed that that env works, wasn't aware of that one before, thanks!

The remaining problem is the hardcoded localhost I guess.

Seems like that may be the only blocker then 👍

@rom1v
Copy link
Collaborator

rom1v commented Nov 17, 2021

OK, then I suggest to add an option --host (in addition to the existing --port).
IMO, it should only configure the scrcpy host (and let the adb host be configured via ADB_SERVER_SOCKET).

Are you interested in working on it (from dev branch) and submitting a PR?

@clienthax
Copy link
Author

Honestly I suck at c/c++, and I haven't had much luck pulling this into an IDE to look at it.
Is there a simple way to do that assuming windows?

@rom1v
Copy link
Collaborator

rom1v commented Nov 17, 2021

Is there a simple way to do that assuming windows?

Yes, from Windows, open your browser, download a Linux ISO, put it on a USB key, install it. Then you are on Linux, and it's easy. :trollface:

More seriously, on Windows, you can build from MSYS2: https://github.com/Genymobile/scrcpy/blob/master/BUILD.md#in-msys2

@clienthax
Copy link
Author

clienthax commented Nov 17, 2021

Hm, So I'm looking at this and it seems to actually be getting stuck here

video_socket = connect_to_server(server, attempts, delay);

Aha.. another localhost

bool ok = net_connect_intr(intr, socket, IPV4_LOCALHOST, port);

With both of these set to the server (from inet_addr, not sure if thats right) I don't seem to be getting far, might have to leave this to you

@clienthax
Copy link
Author

clienthax commented Nov 17, 2021

Another question, does the port argument change where the adb tunnel exits or only where the connection is attempted, because that would need to still be the original port for my setup to work
Eg
External host port 4444 -> docker container port 27183 -> phone
The port inside the container is static, only the external port changes

So the server would need to listen on 27183, and the client would need to connect to external 4444

@rom1v
Copy link
Collaborator

rom1v commented Nov 18, 2021

Aha.. another localhost

This is intended to be the same address.

The reason there are 2 is that once the tunnel is set up, scrcpy attempts to write to it (1038bad):

Due to the tunnel, every connect() will succeed, so the client must
attempt to read() to detect a connection failure. For this purpose, when
using the "adb forward" mode, the server initially writes a dummy byte,
read by the client.

Another question, does the port argument change where the adb tunnel exits or only where the connection is attempted, because that would need to still be the original port for my setup to work
Eg
External host port 4444 -> docker container port 27183 -> phone
The port inside the container is static, only the external port changes

The port is the port redirected by adb forward, and the port scrcpy must connect to to communicate with the server.
If scrcpy talks to host:4444, then it's probably 4444 in your setup.

So the server would need to listen on 27183, and the client would need to connect to external 4444

The server does not even listen on a TCP port, it listens to a unix socket, and adb forward (or adb reverse) redirects the localhost:port on the host to the unix socket on the device.

(the --host option is only meaningful in adb forward mode)

@clienthax
Copy link
Author

forward

so not exactly, the problem is currently that the port in each usb container will always be container 27183 -> phone socket
And the docker proxy forwards say Host 4444 -> (container 27183 -> phone socket)
So I need to be able to set both the port the adb forward occurs on, (so its always 27183 in my case)
And the port the client connects on, which would be 4444, and the host.

I have dragged a friend into helping with this over at https://github.com/RipleyTom/scrcpy/tree/add_remote_options
This would add two options --scrcpy-ip and --scrcpy-port, leaving the existing --port to be used as the forward port

@rom1v
Copy link
Collaborator

rom1v commented Nov 18, 2021

👍 Makes sense. Please open a PR (draft if it's not finished) to discuss more easily on each change if necessary.

I suggest to rename the options --tunnel-host and --tunnel-port (having both a scrcpy option --port and --scrcpy-port is confusing).

rom1v pushed a commit that referenced this issue Nov 19, 2021
In "adb forward" mode, by default, scrcpy connects to localhost:PORT,
where PORT is the local port passed to "adb forward". This assumes that
the tunnel is established on the local host with a local adb server
(which is the common case).

For advanced usage, add --tunnel-host and --tunnel-port to force the
connection to a different destination.

Fixes #2801 <#2801>
PR #2807 <#2807>

Signed-off-by: Romain Vimont <[email protected]>
@rom1v rom1v closed this as completed in 7bdbde7 Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants