No Consistent Way to Connect ADB over TCP - android

I am debugging an Android app that usually crashes when I plug into an Arduino it is supposed to be communicating with. Consequently, I need to get a wireless connection to the device's logcat, which is what brought me to ADB over TPC as seen on the Android developers webpage.
The recommended process is:
C:\Users\User> cd AppData\Local\Android\sdk\platform-tools
C:\Users\User\AppData\Local\Android\sdk\platform-tools> adb kill-server
C:\Users\User\AppData\Local\Android\sdk\platform-tools> adb start-server
* daemon not running; starting now at tcp:5037
* daemon started successfully
C:\Users\User\AppData\Local\Android\sdk\platform-tools> adb tcpip 5555
restarting in TCP mode port: 5555
C:\Users\User\AppData\Local\Android\sdk\platform-tools> adb connect 10.20.5.160:5555
However, the typical response is:
unable to connect to 10.20.5.160:5555: cannot connect to 10.20.5.160:5555: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060)
I could not consistently get a connection between a PC and mobile device. Over the course of three weeks using several networks and devices, I could only connect two times out of an agonizing many attempts.
I have dug deep into the posted questions on stackoverflow and tried literally every recommended alteration to getting an adb connection, from using an Android Studio plugin to forwarding ports to trying several other ports to toggling my device's internet. I still could not get a connection more than a fraction of a percent of the time.
When I look at the network state of my device after adb tpip <port>, I find no evidence of the device trying to look for a connection:
C:\Users\User\AppData\Local\Android\sdk\platform-tools> adb shell
j3ltevzw:/ $ netstat -n
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 ::ffff:10.20.5.160:4214 ::ffff:173.194.196.188: ESTABLISHED
udp 4288 0 adb shell ip -f inet addr show wlan0:68 10.20.5.1:67 ESTABLISHED
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node Path
... ... ... ... ... ...
... ... ... ... ... ...
Also, when I try to ping my device, I usually get:
C:\Users\Benjamin\AppData\Local\Android\sdk\platform-tools> ping 10.20.5.160
Pinging 10.20.5.160 with 32 bytes of data:
Reply from 10.20.5.232: Destination host unreachable.
Reply from 10.20.5.232: Destination host unreachable.
Reply from 10.20.5.232: Destination host unreachable.
Reply from 10.20.5.232: Destination host unreachable.
Ping statistics for 10.20.5.160:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss)
What I am looking for is a process or file that can be run and consistently open a tcp adb connection, or at least explain what about my setup is invalid. Ideas?
Update 1:
I have started a bounty on this question. I feel like the problem with the ADB software used to make connection for debugging is two fold:
adb tcpip <port> does not always invoke the mobile device to listen on the specified port
adb connect <ip>:<port>, I am assuming, is not given permission by the network to connect; I am not a networking expert, but the fact that pinging a device returns "destination host unreachable" seems a little off
I will award the first person to find a successful solution. Seeing that having an ADB USB connection gives a user access to both the mobile device's and host's terminal, there really is no excuse for a connection not to be able to be made between the two.
Update 2:
I have recently had more success in connecting to the ADB as well as receiving successful pings at my school network. Note at this network connects are insecure and the host and mobile devices where on separate subnetworks. Any idea why these conditions would work over my secure network at home that uses only one subnet?

Try starting from scratch and setup ADB-over-tcp following steps below:
Turn off USB debugging on your device and turn it on again (just to reset).
Kill the ADB server on your PC using adb kill-server
Connect your device to the PC using the USB cable and type adb devices. This will automatically restart the ABD server again.
Enter adb tcpip 5555 on your PC terminal. This will switch the adbd daemon on your device to tcp-ip mode.
Disconnect your device from USB. Now connect your device to the same wireless network as your PC, either the same wi-fi or use your phone as a hotspot.
Determine your phone's ip. You can do this in the wi-fi settings on your phone. If you are using your phone as hotspot, then generally your ip should be 192.168.43.1 (not required but most of the time it's the same).
Connect to ADB via tcp using adb connect <IP>
This should hopefully connect your device to your pc via tcp-ip.

I found a solution that works for me, but I feel it shouldn't necessary and it may not applicable for everybody else with these issues, so its still not quite what I was aiming for.
Anyways, after seeing riyaz-ali suggest what an IP address I should be for using a mobile hotstop through a phone, I realized any network complications would be solved if I was the network, so I connected my mobile device to the mobile hotspot on my laptop.
Instant ping responses and immediate ADB connection with the popularly suggested commands.

Just found myself in the same situation. Had no problem yesterday but today couldn't connect.
Solution was simple, I realized that today I'm connected to VPN which obviously makes me belonging to a different network.
So, disconnecting and connection to the same Wi-Fi solved the trouble.

Related

Can't connect through ADB to device's port

I'm trying to connect to a TV set-top box. After issuing "adb connect my_IP_address" I get this error "No connection could be made because the target machine actively refused it. (10061)". I've tried many basic solutions like the ones from this SO thread but they either don't work or I can't attempt them since they require a USB cable connection and my device dosen't respond to that for some reason.
USB debugging is enabled and I'm sure the device is connected to the same network since I successfully pinged it. Surprisingly I discovered that the 5555 port which is usually used for connecting isn't even open. I got that from using Nmap to check for a particular port. Then I used Nmap to see which ports are open and only got 3:
PORT STATE SERVICE
8008/tcp open http
8009/tcp open ajp13
9000/tcp open cslistener
None of those is suitable for a connection and it looks like there is no available port? What can I do from here?
First, you need to open the 5555 port for communication
Step to open the port
plug your device to the pc
issue command to open the port adb start-server 5555
adb connect my_IP_address:5555

adb wifi often go offline, how to keep adb online?

I'm using Android tablet communicating with a USB device through USB port, the tablet only has one usb port, so I use adb wifi as my debug tool. However, when I connect adb through WIFI, the connection won't keep long(only a few minutes us usually), how to keep the adb wifi connection online all the time?
Another question, is it possible to use USB HUB to connect the tablet with both USB flash-drive and my computer, and keep adb running?
Many thanks!!!
After lots of unsuccessful attempts,I have noticed that turning Allow ADB debugging in charge only mode specification on , solved the problem . It makes the device online and accessable over wifi to ADB.
You can find it under Developer options section.
Here is what I found out from researching everywhere and developing on my own for more than a week.
Q1. adb service often crashes if it is not doing any executions for a long long time.
A1. calling adb commands time to time keeps adb server online.
Q2. wifi connected device sometimes disconnect.
A2. Before you check your wifi on the connected device, check the wifi that your ADB server is running on. Ping to google and if it is well connected, ping to the device.
Wireless can disconnect on its own and even wired connection is sometimes disconnected. so calling "adb connect ..." when the device is not already connected is necessary. You could do this easily by saving "adb devices > device.txt" and query out whether your expected wifi is on the list. If not, connect again..(do this in another thread).
Q3. wifi connected device is sometimes offline.
A3. This is because by TCP/IP connection your ADB server is now on Time_Wait stance. The last connection was interrupted that the next connection is now offline because the last connection is not completely shut down. You can either manually disconnect/connect your device's wifi or restart TCPIP connection by ex) "adb tcpip 5555"
If you want to do this automatically, you are going to have to disconnect/connect your device's wifi programmatically.
Leave any other questions and I can answer on the comments.
When connection is lost and adb devices shows device is offline, like this:
prompt> adb devices
List of devices attached
192.168.1.1:5555 offline
then adb disconnect IP followed by adb connect IP will often work:
prompt> adb disconnect 192.168.1.1
disconnected 192.168.1.1
prompt> adb devices
List of devices attached
prompt> adb connect 192.168.1.1
connected to 192.168.1.1
prompt> adb devices
List of devices attached
192.168.1.1:5555 device
Use adb over wi-fi without any third-party apps. Follow the steps.
Connect device via USB
Open your terminal and check your device is listed with adb devices command
Type adb tcpip 5555 and enter (or use another port instead of 5555)
Plug out your USB cable. You don't need it anymore.
Take your Android phone and go Settings/About/Status
Check the IP address part. Let's say your IP address is 192.168.x.y
In your terminal, write the command adb connect 192.168.x.y
Now, you have connected your device via wi-fi.
You can see your device in adb devices
Enjoy it! :)
This seems like an issue with your wifi. As a precaution, just keep the terminal open and whenever you need to test just press the 'UP arrow' key to get to previously ran adb connect "<ip>" command.
I tried many ways but this one worked out for me:
force the display on and of in a loop would keep the device online
adb shell input keyevent 224
timeout 2
adb shell input keyevent 26
timeout 58
this turns the display on every minute for 2 seconds
So, I'm using Scrcpy and Adb to wirelessly connect to my Phone(for developing Flutter Apps) and since the screen wasn't staying awake even by Scrcpy --stay-awake command.
I had to change Lock Settings=>Lock Screen => Sleep, and settings to Never Sleep.

ADB over ethernet

I have an android device which I want to connect to using ADB. For reasons that don't matter here I need it to have an ethernet connection, not wifi. The device itself refuses to have both ethernet and wifi connections at the same time.
I have been using a third party app called ADB WiFi to connect to it with ADB when it is in WiFi mode, and I have found that I can connect to it in wifi, then switch the device into ethernet, and then reconnect to the new IP, and it works.
I would dearly like to be able to connect to my device (which is often remote and hard to reach) without first switching it into wifi and back, to which end I have written my own little app which uses SU and does:
setprop service.adb.tcp.port 5555
stop adbd
start adbd
It says that it is working when I run it and produces no error messages, but I can't connect afterwards. It doesn't work in wifi mode either. After setting up a connection once using the 3rd party app, I can then use stop adbd to prevent adb working, and I can use my application above to enable it again, without wifi or 3rd party intervention, which suggests that it is doing what it thinks it is doing, but missing a one off step.
Does anyone know if there is another thing that must be set / enabled / poked in order for adbd to work? Does anyone know what I'm missing?
Thanks
Have you tried this:
adb tcpip 5555
adb connect 192.168.1.1:5555
replacing the 192.168.1.1 with your phones IP Address?
I was able to get both ADB (through USB) and Ethernet, but it was device specific. I used the Asus Transformer Pad TF701T with the keyboard dock. The dock allowed me to connect the ADB cable and provided a full size USB port. I connected a compatible USB to Ethernet adapter to get Ethernet.

Unable to connect Android ADB over TCP/IP

I'm trying to get the Android Debug Bridge working over wifi from my 64-bit Windows 7 desktop computer to my Nexus10. I connect the device over USB, and then I followed "How can I connect to Android with ADB over TCP?, but I end up with an error message that it can't connect:
C:\adt-bundle\sdk\platform-tools>adb usb
restarting in USB mode
C:\adt-bundle\sdk\platform-tools>adb devices -l
List of devices attached
R32D300NXJV device product:mantaray model:Nexus_10 device:manta
C:\adt-bundle\sdk\platform-tools>adb tcpip 5555
restarting in TCP mode port: 5555
C:\adt-bundle\sdk\platform-tools>adb connect 192.168.231.2
unable to connect to 192.168.231.2:5555
To start debugging this, I tried pinging the Nexus10 from my desktop computer. Both devices are connected to the same router, by a cable in the case of the desktop computer, and wirelessly for the Nexus10. However, I got
C:\adt-bundle\sdk\platform-tools>ping 192.168.231.2
Pinging 192.168.231.2 with 32 bytes of data:
Reply from 192.168.231.61: Destination host unreachable.
Reply from 192.168.231.61: Destination host unreachable.
Reply from 192.168.231.61: Destination host unreachable.
Reply from 192.168.231.61: Destination host unreachable.
Ping statistics for 192.168.231.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
The IP address 192.168.231.61 which returns "Destination host unreachable" is the IP address of my desktop computer. Although the ping doesn't work, I don't know whether the fact that I can't ping is the source of my ADB problem or whether it's unconnected to the issue.
I'm running Android Debug Bridge version 1.0.31. Can anyone help?
This must have been a networking problem, because when I connected via a wireless network on a different subnet, then (1) I was able to ping the nexus10 from my desktop, and (2) ADB connected over TCPIP OK. So my conclusion is that my desktop/router/nexus10 had some bizarre routing incompatibility when on the same subnet, when disappeared when they were on different subnets.
Thanks anyway.
I have problems both with my nexus 4 and my nexus 10 on the same wifi as my laptop. The nexus 4 I have had more time to experiment with, and what helps is either rebooting the phone, or using "DNS Hostname Changer" to restart networking and then I can connect again.
The Nexus 10 seems to be a bit worse than Nexus 4 though....

adb logcat on a real phone using tcp/ip

Can I dump logs from an android phone over wifi (using tcp/ip) using adb? adb connect can be used, but it needs some server to be running on the phone (at 5555 port). How do I start this server?
Or the only way to get logs from a phone is by connecting it as a USB device?
Install adbWireless on your phone. Run the application and click on the big button (you cannot miss it!). It will activate ADB over Wifi and display the URL to use to connect to it with the adb command.
On your computer, run the adb command with the connect parameter. The usage for adb says:
connect <host>[:<port>] - connect to a device via TCP/IP
Port 5555 is used by default if no port number is specified.
Obviously the computer and the smartphone must be on the same Wifi network.
zero4
All you are trying to do is drop adb logcat command on the device & send output stream to a remote location. I would suggest, read this post about how to run shell commands in your app.
The summary is
Run "adb logcat"
Collect Output Stream of the command in a file on device
& Finally post that file to your local server OR Manually pull that file from device
The post contains link to everything you are looking for.
Android is very paranoid when it comes to network access. Without root access, you can't really run any servers, just clients. In short, without root, look at the answer from 100rabh.
If you do have root, you could either open up your network stack for incoming connections on port 5555, or you could hack adb to do the inverse connection (that is, connect to your client). The latter is way more secure and shouldn't really be to hard to do. (I haven't looked at the code for a while, though.) The communication bits for all parts of adb is handled in one and the same library, for all three parts of adb (server, daemon and client).
By the way, what you refer to as a server on the phone is really the adb daemon.

Categories

Resources