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

Using scrcpy Wirelessly Not Working in Latest Build #386

Closed
Zakkumaru opened this issue Jan 6, 2019 · 28 comments
Closed

Using scrcpy Wirelessly Not Working in Latest Build #386

Zakkumaru opened this issue Jan 6, 2019 · 28 comments
Labels

Comments

@Zakkumaru
Copy link

For the record, it has never actually worked for me, wirelessly. I can get it to work with wired adb, but not wirelessly.

Full issue described here.

Basically, I always get the "connection rejected" error, no matter what I try.

:~$ scrcpy -s 192.168.1.150:5555 -m 800 -b 2M
/usr/local/share/scrcpy/scrcpy-server....shed. 1.1 MB/s (19038 bytes in 0.017s)
error: more than one device/emulator
ERROR: "adb reverse" returned with value 1
WARN: 'adb reverse' failed, fallback to 'adb forward'
ERROR: Exception on thread Thread[main,5,main]
java.io.IOException: Connection refused
	at android.net.LocalSocketImpl.connectLocal(Native Method)
	at android.net.LocalSocketImpl.connect(LocalSocketImpl.java:292)
	at android.net.LocalSocket.connect(LocalSocket.java:145)
	at com.genymobile.scrcpy.DesktopConnection.connect(DesktopConnection.java:32)
	at com.genymobile.scrcpy.DesktopConnection.open(DesktopConnection.java:37)
	at com.genymobile.scrcpy.Server.scrcpy(Server.java:13)
	at com.genymobile.scrcpy.Server.main(Server.java:70)
	at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
	at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:287)

So, I was requested to open an issue here. I have seen many posts like this, already, however, and they each seem to end up getting closed despite no resolution.

@rom1v rom1v added the adbtcp label Jan 6, 2019
@rom1v
Copy link
Collaborator

rom1v commented Jan 6, 2019

Thank you for your report.

I added some logs that should help investigating the issue. Could you checkout branch issue386 and try again, please?

Compile the whole project (do not use the prebuilt server) in debug mode:

meson d
ninja -Cd
./run d

Then copy/paste the output in the console.

Thank you for your help.

@Zakkumaru
Copy link
Author

$ ./run d -s 192.168.1.150:5555 -m 800 -b 2M 
d/server/scrcpy-server.jar: 1 file pushed. 1.6 MB/s (27919 bytes in 0.017s)
error: more than one device/emulator
ERROR: "adb reverse" returned with value 1
WARN: 'adb reverse' failed, fallback to 'adb forward'
DEBUG: tunnel_forward=1
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
DEBUG: Remaining connection attempts: 94
DEBUG: Remaining connection attempts: 93
DEBUG: Remaining connection attempts: 92
DEBUG: Remaining connection attempts: 91
DEBUG: Remaining connection attempts: 90
DEBUG: Remaining connection attempts: 89
DEBUG: Remaining connection attempts: 88
DEBUG: Remaining connection attempts: 87
DEBUG: Remaining connection attempts: 86
DEBUG: Remaining connection attempts: 85
DEBUG: args: [800, 2000000, true, , false]DEBUG: Remaining connection attempts: 84

DEBUG: tunnelForward = true
DEBUG: Starting decoder thread
DEBUG: Starting controller thread
INFO: OpenGL shaders: ENABLED
INFO: Created renderer: opengl
INFO: Initial texture: 448x800

NOW it works? Are you sure debugging is the only thing you changed? (Rhetorical, since I can read the commit)

Thanks for all the help. Strange it's not working for me on the main build, considering it's also v1.5.

Can we just make the debugging an argument? I think we need the option to be included in the main build, considering how useful it would be. It would help me figure out why it's not working in the main build, and why it keeps crashing when I use USB mode.

@rom1v
Copy link
Collaborator

rom1v commented Jan 7, 2019

NOW it works

Could you try at v1.5-fixversion (a17f111)?
And at master (0e019f8)?

Which ones work?

Can we just make the debugging an argument?

It's a build argument (just do not pass --buildtype release as a meson argument).

But I guess you mean a runtime parameter, like a "verbose" mode?

@Zakkumaru
Copy link
Author

Zakkumaru commented Jan 7, 2019

Could you try at v1.5-fixversion (a17f111)?
And at master (0e019f8)?

Which ones work?

Give me a few minutes to build and test each one.

It's a build argument (just do not pass --buildtype release as a meson argument).

But I guess you mean a runtime parameter, like a "verbose" mode?

Yeah, I thought you would assume I meant a runtime argument. I think there need to be varying levels of details for the runtime debugging flags, just so people don't have to sift through all the logs, if verbose is too much.

@Zakkumaru
Copy link
Author

Okay, both builds you asked about work for me. However, I don't think this is a valid test, since I received the same debugger messages as your debugger build. I ran from the builds themselves (./run d), in the actual directories of the downloaded commits, and not general commands, like scrcpy, so I'm not entirely sure how to completely reset everything to conduct a more valid test.

@rom1v
Copy link
Collaborator

rom1v commented Jan 7, 2019

I'm not entirely sure how to completely reset everything to conduct a more valid test.

Use a separate build directory in release mode:

meson somedir --buildtype release --strip -Db_lto=true
ninja -Csomedir
./run somedir

@Zakkumaru
Copy link
Author

Alright, that looks more like it.
They're all working. Idk wtf was wrong, before. I swear, things will break right up until the point I get the dev's attention, then it works just to make me look bad. Haha

@codeskyblue
Copy link

codeskyblue commented Jan 12, 2019

Now working for me. Only output

22:11 $ scrcpy -s 192.168.1.23:5555
/usr/local/Cellar/scrcpy/1.3/share/scrcpy/scrcpy... 1 file pushed. 1.0 MB/s (18570 bytes in 0.017s)
error: more than one device/emulator
2019-01-12 22:11:29.626 scrcpy[25630:3011746] ERROR: "adb reverse" returned with value 1
2019-01-12 22:11:29.627 scrcpy[25630:3011746] WARN: 'adb reverse' failed, fallback to 'adb forward'
error: device offline
2019-01-12 22:11:29.659 scrcpy[25630:3011746] ERROR: "adb forward" returned with value 1

No window opened

the adb logcat quit when using this command

@rom1v
Copy link
Collaborator

rom1v commented Jan 12, 2019

What does adb logcat say?

@rom1v
Copy link
Collaborator

rom1v commented Jan 12, 2019

It should not. What is the result of adb devices?

@codeskyblue
Copy link

Maybe my fault. I try to write a adb-usb to tcp proxy. some code may not working.

@codeskyblue
Copy link

codeskyblue commented Jan 13, 2019

I debug for a long time, but still do not know why.

Here is my tool which can share usb device over WIFI. https://github.com/codeskyblue/fa

# assume this pc ip is 10.0.0.1
$ fa share --port 5555

In another pc

$ adb connect 10.0.0.1
$ scrcpy -s 10.0.0.1:5555
/usr/local/Cellar/scrcpy/1....B/s (18570 bytes in 0.011s)
error: reverse service not supported
2019-01-13 13:14:17.471 scrcpy[55728:3248464] ERROR: "adb reverse" returned with value 1
2019-01-13 13:14:17.471 scrcpy[55728:3248464] WARN: 'adbreverse' failed, fallback to 'adb forward'
2019-01-13 13:14:17.662 scrcpy[55728:3248464] ERROR: Could not retrieve device information

I don't know why it prints Could not retrieve device information, It seems fa did not accept requests about information request.

Hope to hear from you soon. @rom1v

@rom1v
Copy link
Collaborator

rom1v commented Jan 13, 2019

I don't know why it prints Could not retrieve device information

On start, scrcpy client opens a socket (on port 27183) to communicate with the server (executed on the device).
"Device information" is the first piece of data which is read: https://github.com/Genymobile/scrcpy/blob/v1.5/app/src/device.c#L8

If this fails, the reason is probably that the socket is not connected between the client and the server.

In "forward" mode, the client connects to localhost:27183 (which is tunneled via adb forward). If you use your own additional tunnel, you need to make sure this port is correctly forwarded. #144 (comment)

Typically, if you use your own tunnel, #144 (comment)

@codeskyblue
Copy link

I'm pretty sure adb forward works fine. Another similar tool https://www.vysor.io/ works fine.
But scrcpy donot.

I traced command executed in tunnel. Aborted in jar.

When call app_process, trace dumped. Aborted

$ adb push /usr/local/share/scrcpy/scrcpy-server.jar  /data/local/tmp
$ adb shell CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 0 8000000 true
Aborted

@rom1v
Copy link
Collaborator

rom1v commented Jan 13, 2019

Are there any relevant logs in adb logcat when you execute this? Which version of scrcpy? (the arguments passed to the server depend on the version)

Does it work over usb?

Is Android >= 5.0?

@codeskyblue
Copy link

codeskyblue commented Jan 13, 2019

I installed scrcpy through brew install scrcpy

There is no relevent log in adb logcat

20:45 $ scrcpy -v
scrcpy v1.3

dependencies:
 - SDL 2.0.8
 - libavcodec 58.18.100
 - libavformat 58.12.100
 - libavutil 56.14.100

$ adb -s 192.168.1.23:6174 shell getprop | grep sdk
[ro.build.version.preview_sdk]: [0]
[ro.build.version.sdk]: [23]
[ro.qc.sdk.audio.fluencetype]: [none]
[ro.qc.sdk.audio.ssr]: [false]

Yes it works over usb. And If you use adb tcpip 5555 to turn device into wifi mode, it works too.

@codeskyblue
Copy link

codeskyblue commented Jan 14, 2019

Finally find out the problem.

When run this command

adb shell CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 0 8000000 true

Another command calls in another thread.

adb shell rm /data/local/tmp/scrcpy-server.jar

So app_process can not found scrcpy-server.jar, Aborted shows in output.

One solution to solve this problem is to delay 1 second, and then call rm /data/local/tmp/scrcpy-server.jar. What do you think @rom1v

@codeskyblue
Copy link

codeskyblue commented Jan 14, 2019

Looks like relevent with #390

@rom1v
Copy link
Collaborator

rom1v commented Jan 14, 2019

@codeskyblue The client removes the file as soon as it is connected with the server:
https://github.com/Genymobile/scrcpy/blob/master/app/src/server.c#L233

The problem with an additional tunnel is that from the client point of view, the connection will succeed as soon as it is connected to the tunnel, even if the server is not started yet, so it will remove the server before even starting it.
I had a similar issue in gnirehtet (see commit message Genymobile/gnirehtet@47fae70).

Here, even if we don't remove the server, this is still racy: any read() occurring too soon on the tunneled socket will fail.

Currently, I have no race-free solution. I started a background thread in my mind to think about it. 😉

@codeskyblue
Copy link

Maybe you can retry connect when fails?

@codeskyblue
Copy link

And I found if you start the jar server already, scrcpy can works fine all the time.

rom1v added a commit that referenced this issue Jan 14, 2019
To clean up the device, the client executed "adb shell rm" once the
server was guaranteed to be started (after the connection succeeded).

This implied to track whether the installation state, and failed if an
additional tunnel was used in "forward" mode:
<#386 (comment)>

Instead, make the server unlink itself on start.
@rom1v
Copy link
Collaborator

rom1v commented Jan 14, 2019

@codeskyblue I have no idea why I cleaned up the device from the client.

On dev, I clean from the server: 39c5e71.
It should fix your problem.

@Genymobile Genymobile deleted a comment from codeskyblue Jan 14, 2019
@codeskyblue
Copy link

Sorry @rom1v even you don't delete jar file it is still say Aborted. I think maybe when app_process called, maybe the first connect may fail because of server is still starting

@codeskyblue
Copy link

And I don't think it is a good idea to unlink in jar. It will make it hard to debug issues.

@rom1v
Copy link
Collaborator

rom1v commented Jan 15, 2019

I think maybe when app_process called, maybe the first connect may fail because of server is still starting

In "forward" mode, it retries if it fails.

Oh, what I said here is incorrect: the problem of connect-without-read when a tunnel is present is already managed: 1038bad.

You should try to increase the number of connection attempts.

EDIT: In fact, it can't be the cause of an Abort.

And I don't think it is a good idea to unlink in jar. It will make it hard to debug issues.

The purpose is to leave nothing on the device once disconnected. It's trivial to comment unlinkSelf() for debugging purpose.

@rom1v
Copy link
Collaborator

rom1v commented Jan 15, 2019

Sorry @rom1v even you don't delete jar file it is still say Aborted

Oh. So it's not related. Is the file correctly copied?

@codeskyblue
Copy link

yes the file is correctly copied

@ryanliang88
Copy link

Idk if your issue has anything to do with mine, but I just recently closed my issue with steps on how to fix.

#390 (comment)

@rom1v rom1v closed this as completed Jun 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants