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

Add --tcpip option to automate TCP/IP (wireless) connections #2827

Merged
merged 13 commits into from
Nov 29, 2021
Merged

Add --tcpip option to automate TCP/IP (wireless) connections #2827

merged 13 commits into from
Nov 29, 2021

Conversation

rom1v
Copy link
Collaborator

@rom1v rom1v commented Nov 25, 2021

Add an option to configure the TCP/IP connection automatically. There are two variants.

If the device (accessible at 192.168.1.1 in this example) already listens on a port (typically 5555) for incoming adb connections, then run:

scrcpy --tcpip=192.168.1.1       # default port is 5555
scrcpy --tcpip=192.168.1.1:5555

If the device TCP/IP mode is disabled (or if you don't know the IP address), connect the device over USB, then run:

scrcpy --tcpip    # without arguments

It will automatically find the device IP address (by parsing adb shell ip route), enable TCP/IP mode, then connects to the device before starting.


This feature is available in scrcpy v1.21.

obsolete

Here are binaries so that you can test easily. Please replace these files in your v1.20 release:

  • scrcpy.exe sha256:c3d96408d81d4c3f17259a8d99bd2e343f6c9758dc85e6317b114f6cdc95fd00
  • scrcpy-server sha256:e08e9aa4796c213bf601f6323b5e9f4fce250b1f3b1d46441289824cb4af294a
old binaries v3
  • scrcpy.exe sha256:67068f06190a5454ca245290022da84549a8d23c5c90926ddf2a558a20e2d0f8
  • scrcpy-server sha256:e08e9aa4796c213bf601f6323b5e9f4fce250b1f3b1d46441289824cb4af294a
old binaries v2
  • scrcpy.exe sha256:1931c1637fb35c453d35b416cc0bcbefcf25806f79d52eb3cec3d5fc78a26a05
  • scrcpy-server sha256:e08e9aa4796c213bf601f6323b5e9f4fce250b1f3b1d46441289824cb4af294a
old binaries v1
  • scrcpy.exe sha256:e77f3140f90353ad5b724576df9f1223717c24927ea4255714c122d5a956451a
  • scrcpy-server sha256:e08e9aa4796c213bf601f6323b5e9f4fce250b1f3b1d46441289824cb4af294a

Please test and report any issue you might encounter. This is also built from the current dev branch (so with code which will be in the next release), where I did a lot of refactors recently, so please report any regression. That would help a lot 😉

Thank you for your feedback.

@rom1v rom1v changed the base branch from master to dev November 25, 2021 21:58
@rom1v rom1v force-pushed the tcpip branch 2 times, most recently from 0fa96eb to 8429e43 Compare November 26, 2021 08:42
@rom1v rom1v mentioned this pull request Nov 26, 2021
@Helaer
Copy link

Helaer commented Nov 27, 2021

@rom1v I have a Huawei mobile phone and a Xiaomi mobile phone, I did a test separately, scrcpy --tcpip=192.168.1.1 # default port is 5555
scrcpy --tcpip=192.168.1.1:5555 These two options are no problem,You can directly connect to the device IP address and start the screen projection window. The scrcpy --tcpip # without arguments option is only valid on my Huawei phone, and on Xiaomi phones Unable to automatically connect to IP.

@Helaer
Copy link

Helaer commented Nov 27, 2021

shell ip route

Huawei mobile phone obtains IP log:

D:\scrcpy-win64-v1.20>adb -s 66J5T19614020092 shell ip route
192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.6

Xiaomi mobile phone obtains IP log:

D:\scrcpy-win64-v1.20>adb -s e2b16c shell ip route
10.90.227.156/30 dev rmnet_data4 proto kernel scope link src 10.90.XXX.XXX
192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.7

Both mobile phones are connected to the Wi-Fi network at the same time. The difference is that the phone card is not inserted in the Huawei mobile phone, and the phone card is inserted in the Xiaomi mobile phone. I think you should start with the analysis of keywords in dev wlan0 proto kernel scope link src.

@rom1v
Copy link
Collaborator Author

rom1v commented Nov 27, 2021

OK, thank you for your test.

For now, it always retrieves the ip from the first line of adb shell ip route. I will change to consider the first line where the 3rd column starts with wlan.

@rom1v
Copy link
Collaborator Author

rom1v commented Nov 28, 2021

I pushed a new version, please re-test 😉

@Helaer
Copy link

Helaer commented Nov 29, 2021

@rom1v I tested it on Xiaomi and Huawei devices respectively, and --tcpip work well.

Let the caller decide if stdout and stderr must be inherited on process
creation, i.e. if stdout and stderr of the child process should be
printed in the scrcpy console.

This allows to get output and errors for specific adb commands depending
on the context.

PR #2827 <#2827>
Explicitly indicate, for each adb call, if stdout and stderr must be
inherited.

PR #2827 <#2827>
In addition to disable stdout and stderr of the child process, add a
flag to disable the error log printed by scrcpy if the command failed.

This will we useful for commands which are expected to fail in some
cases (like "adb disconnect" if the device is not connected).

PR #2827 <#2827>
"adb connect" always returns successfully (with exit code 0), even in
case of failure.

As a workaround, capture its output and check if it starts with
"connected".

PR #2827 <#2827>
This will help to parse the result of "adb shell ip route" to find the
device IP address.

PR #2827 <#2827>
Depending on the platform and adb versions, the lines output by adb
could end with "\r\r\n". This util function helps to remove all trailing
'\r'.

PR #2827 <#2827>
Parse the result of "adb shell ip route" to find the device IP address.

PR #2827 <#2827>
Expose a function to execute "adb tcpip <port>".

PR #2827 <#2827>
This will allow to read the property "service.adb.tcp.port" to know if
the TCP/IP mode is enabled on the device, and which listening port is
used.

PR #2827 <#2827>
This improves readability, and makes the function reusable.

PR #2827 <#2827>
Expose an option to automatically configure and reconnect the device
over TCP/IP, to simplify wireless connection without using adb
explicitly.

There are two variants:
 - If a destination address is provided, then scrcpy connects to this
   address before starting. The device must listen on the given TCP port
   (default is 5555).
 - If no destination address is provided, then scrcpy attempts to find
   the IP address of the current device (typically connected over USB),
   enables TCP/IP mode, then connects to this address before starting.

PR #2827 <#2827>
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

Successfully merging this pull request may close these issues.

2 participants