Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
110.51k stars 10.59k forks source link

Connection is rejected after unplugging the device from computer #842

Open rdlf4 opened 5 years ago

rdlf4 commented 5 years ago

So, this has happened to me all the time I need to recharge my phone, and I do so by plugging it to my computer. But normally, after it's been charged and unplugged, trying to connect to my phone again via wireless by issuing the command

adb connect 192.168.0.101

returns me with an error:

unable to connect to 192.168.0.101:5555: Connection refused

Then, I have to plug it to my computer again, do the same as I did before:

adb forward tcp:5555 tcp:7612

And then, do:

adb tcpip 7612

So that, my phone returns:

restarting in TCP mode port: 7612

And then, it finally connects.

My question is, why is it that every time I unplug it from my computer, it no longer works in TCP mode? Can't I leave it like that, in order to not have to re-do those steps after unplugging my device?

rom1v commented 5 years ago

Indeed, on some devices, disconnecting the USB cable breaks the adb-over-tcp connection. There are several threads about this on stackoverflow, but no real solution AFAIK.

rdlf4 commented 4 years ago

I can confirm this issue is still present on v1.12. With my device connected via USB, I do adb tcpip 5555. Right after that, Scrcpy has no problem to find and connect to my phone. However, after restarting my computer, my phone returns:

unable to connect to 192.168.0.101:5555: Connection refused

For those who're wondering, I have no port-managing app on my phone nor any Firewall. And yes, my computer can still ping to my phone.

rom1v commented 4 years ago

I can confirm this issue is still present on v1.12.

The issue is independant from scrcpy, it's just adb.

https://stackoverflow.com/questions/33462720/adb-unable-to-connect-to-192-168-1-105555

dbdonb commented 4 years ago

I can confirm this issue is still present on v1.12. With my device connected via USB, I do adb tcpip 5555. Right after that, Scrcpy has no problem to find and connect to my phone. However, after restarting my computer, my phone returns:

unable to connect to 192.168.0.101:5555: Connection refused

For those who're wondering, I have no port-managing app on my phone nor any Firewall. And yes, my computer can still ping to my phone.

Hi,

Were you able to fix that issue?

The same happens to me. Once I restart my computer or the phone, I'm forced to connect Phone via USB and then enable adb over TCP everytime.

rdlf4 commented 4 years ago

I can confirm this issue is still present on v1.12. With my device connected via USB, I do adb tcpip 5555. Right after that, Scrcpy has no problem to find and connect to my phone. However, after restarting my computer, my phone returns:

unable to connect to 192.168.0.101:5555: Connection refused

For those who're wondering, I have no port-managing app on my phone nor any Firewall. And yes, my computer can still ping to my phone.

Hi,

Were you able to fix that issue?

The same happens to me. Once I restart my computer or the phone, I'm forced to connect Phone via USB and then enable adb over TCP everytime.

Hello. I was not able to fix it. However, there's a chance my computer will connect to my phone without having to plug it to my computer and re-enable adb-over-tcp connection. It's a hit or miss thing. But when that happens, it performs really really slow. My phone takes longer to detect a click event and scrolling is also affected. Really weird. Checked my router's firewall - including LAN Firewall to see whether there are ports that have been restricted or blacklisted, but there's nothing there.

I'm in the dark and out of ideas.

dbdonb commented 4 years ago

I can confirm this issue is still present on v1.12. With my device connected via USB, I do adb tcpip 5555. Right after that, Scrcpy has no problem to find and connect to my phone. However, after restarting my computer, my phone returns:

unable to connect to 192.168.0.101:5555: Connection refused

For those who're wondering, I have no port-managing app on my phone nor any Firewall. And yes, my computer can still ping to my phone.

Hi, Were you able to fix that issue? The same happens to me. Once I restart my computer or the phone, I'm forced to connect Phone via USB and then enable adb over TCP everytime.

Hello. I was not able to fix it. However, there's a chance my computer will connect to my phone without having to plug it to my computer and re-enable adb-over-tcp connection. It's a hit or miss thing. But when that happens, it performs really really slow. My phone takes longer to detect a click event and scrolling is also affected. Really weird. Checked my router's firewall - including LAN Firewall to see whether there are ports that have been restricted or blacklisted, but there's nothing there.

I'm in the dark and out of ideas.

Hi,

Thanks for the quick response.

Looks like it automatically disables the adb tcp connection after sometime of idle, something similar the "remember me" cookies on websites. I hope that's not the case though.

rdlf4 commented 4 years ago

I'll have a look into that once I get back home. I just hope this isn't anything that requires rooting the phone in order to change or even disable it.

dbdonb commented 4 years ago

I'll have a look into that once I get back home. I just hope this isn't anything that requires rooting the phone in order to change or even disable it.

Sure, keep us posted at your convenience. Thanks.

cardboardcode commented 4 years ago

@rdlf4 Hi all, I encountered a similar error to yours as I was setting up the wireless use of scrcpy. I managed to resolve my issue using the following step.

[Possible Solution]

Enable Allow ADB Debugging in charge only mode as shown in the picture attached. [Stackoverflow Reference] Screenshot from 2020-05-20 19-14-50

Hopefully this helps.

If this is indeed the problem, we will need to update the setup instructions for scrcpy wireless connection in the README.md. @rom1v I will be glad to do a quick Pull Request to update the documentation.

rom1v commented 4 years ago

If that's the problem, yes, you could submit a new entry in FAQ.md :+1:

rdlf4 commented 4 years ago

@cardboardcode Thanks for taking the time to look into this. Unfortunately it seems that option you mentioned isn't available for Android 7.x-based devices, mine included. Matter fact, it seems I can only Enable USB debugging, revoke authorizations, and that's it. As you can see from the screenshot attached. scrcpydbug1

Question is, where do I go from here? :/

cardboardcode commented 4 years ago

@rdlf4 It seems the suggested solution only applies to devices of Android 8.0 and above.

Since I am not an expert on this issue, I can only recommend a crude workaround or generic advice:

  1. Upgrade to Android 8.0 and above.
  2. Find the equivalent to Allow ADB Debugging in charge only mode within Android 7.0.

@rom1v It does not seem to be the problem, at least in the specific context of this issue thread.

NLHybrid commented 4 years ago

@rdlf4 Hi all, I encountered a similar error to yours as I was setting up the wireless use of scrcpy. I managed to resolve my issue using the following step.

[Possible Solution]

Enable Allow ADB Debugging in charge only mode as shown in the picture attached. [Stackoverflow Reference] Screenshot from 2020-05-20 19-14-50

Hopefully this helps.

If this is indeed the problem, we will need to update the setup instructions for scrcpy wireless connection in the README.md. @rom1v I will be glad to do a quick Pull Request to update the documentation.

I was successful in getting a connection after following these steps.

Karkunow commented 4 years ago

@NLHybrid @cardboardcode @rdlf4 this trick with enabling "Allow ADB debug in charge only mode" has helped me too! Thanks! Someone should add this to the Readme.md

Uj947nXmRqV2nRaWshKtHzTvckUUpD commented 4 years ago

To permanently enable adb via wifi that will persist upon reboot, login as root in termux and issue command:

setprop persist.adb.tcp.port 5555

In case things go really bad and adbd crashes (but shouldn't be the case normally), you can restart it in termux using root with:

stop adbd
start adbd

No need to plug usb cable anymore afterwards.

rdlf4 commented 4 years ago

I've never heard of "setprob". Should there be a space between the two words? My bad, I misread that, it's "setproP" - still, it's unknown to me. Terminal also complains with command not found.

EDIT #3: I seem to have found a fix. One should issue the command: adb shell setprop persist.adb.tcp.port 5555 Now the next step would be to make sure it sticks, but when I did: adb shell getprop persist.adb.tcp.port It should've returned 5555 but instead, I got nothing.

EDIT #4: Issuing those commands as sudo makes no difference

EDIT #5: I tried restarting the phone since those commands are supposed to 'persist', so maybe they would show some result after it restarts. No, it doesn't.

Uj947nXmRqV2nRaWshKtHzTvckUUpD commented 4 years ago

@rdlf4 yes you can pass the command with adb shell. What I wrote above was directly into android's shell (via termux app)

To do that, you need however to become root to modify system props. So use this instead:

adb shell "su -c 'setprop persist.adb.tcp.port 5555'"
adb shell getprop persist.adb.tcp.port

Update: now i read your edits. Do you get any error? Also what android version do you have?

rdlf4 commented 4 years ago

@rdlf4 yes you can pass the command with adb shell. What I wrote above was directly into android's shell (via termux app)

To do that, you need however to become root to modify system props. So use this instead:

adb shell "su -c 'setprop persist.adb.tcp.port 5555'"
adb shell getprop persist.adb.tcp.port

Update: now i read your edits. Do you get any error? Also what android version do you have?

I couldn't become root (SU) when using Termux, which seems to require my phone to be rooted. Lots of work related stuff on there to even think about it, so I'm avoiding rooting my phone for now. Is there no other way to get this done without rooting the phone? Like an Android app that you know of that allows SU in Termux?

Uj947nXmRqV2nRaWshKtHzTvckUUpD commented 4 years ago

su implies having root access. You will make your life easier if you root your phone than trying to mess around with props in other ways. My advice for rooting is magisk. Depending on the android version you might need to follow a different approach. xda forums is a good place to start.

edit: i think you could however install custom recovery (TWRP) , mount system as read-write and modify build.props from there. No root needed. Worth a try..

What android version do you have?

Uj947nXmRqV2nRaWshKtHzTvckUUpD commented 3 years ago

I created this tool to ease wireless connectivity. Check it out and let me know of your experience.

https://github.com/fusionneur/ethernally