Why does ADB over wifi take multiple attempts to connect? - adb

When connecting to my phone over WiFi using ADB I issue the command adb connect <ip address> however it typically takes 3 to 10 tries before the command works, why?
A typical session is show below, I'm changing nothing between when each command is run, yet eventually it magically works. Once it starts working, it continues to work.
I have port 5555 forwarded and wireless ADB enabled on my phone.
gavin#gavin-Inspiron-N5010 ~ $ adb devices
List of devices attached
gavin#gavin-Inspiron-N5010 ~ $ adb connect 192.168.0.8
unable to connect to 192.168.0.8:5555
gavin#gavin-Inspiron-N5010 ~ $ adb connect 192.168.0.8
unable to connect to 192.168.0.8:5555
gavin#gavin-Inspiron-N5010 ~ $ adb connect 192.168.0.8
unable to connect to 192.168.0.8:5555
gavin#gavin-Inspiron-N5010 ~ $ adb connect 192.168.0.8
unable to connect to 192.168.0.8:5555
gavin#gavin-Inspiron-N5010 ~ $ adb connect 192.168.0.8
unable to connect to 192.168.0.8:5555
gavin#gavin-Inspiron-N5010 ~ $ adb connect 192.168.0.8
unable to connect to 192.168.0.8:5555
gavin#gavin-Inspiron-N5010 ~ $ adb connect 192.168.0.8
unable to connect to 192.168.0.8:5555
gavin#gavin-Inspiron-N5010 ~ $ adb connect 192.168.0.8
unable to connect to 192.168.0.8:5555
gavin#gavin-Inspiron-N5010 ~ $ adb connect 192.168.0.8
unable to connect to 192.168.0.8:5555
gavin#gavin-Inspiron-N5010 ~ $ adb connect 192.168.0.8
unable to connect to 192.168.0.8:5555
gavin#gavin-Inspiron-N5010 ~ $ adb connect 192.168.0.8
unable to connect to 192.168.0.8:5555
gavin#gavin-Inspiron-N5010 ~ $ adb connect 192.168.0.8
connected to 192.168.0.8:5555
gavin#gavin-Inspiron-N5010 ~ $ adb devices
List of devices attached
192.168.0.8:5555 device
gavin#gavin-Inspiron-N5010 ~ $ adb disconnect 192.168.0.8
gavin#gavin-Inspiron-N5010 ~ $ adb devices
List of devices attached
gavin#gavin-Inspiron-N5010 ~ $ adb connect 192.168.0.8
connected to 192.168.0.8:5555
gavin#gavin-Inspiron-N5010 ~ $ adb disconnect 192.168.0.8
gavin#gavin-Inspiron-N5010 ~ $ adb connect 192.168.0.8
connected to 192.168.0.8:5555

Related

adb server always restarts: adb server version (40) doesn't match this client (41)

I can't debug the application to the emulator because adb is unstable as shown in the log below, I tried to do the adb device command three times but the results are different, how do I fix it?
$ adb devices
List of devices attached
emulator-5554 device
$ adb devices
adb server version (40) doesn't match this client (41); killing...
daemon started successfully
List of devices attached
emulator-5554 offline
$ adb devices
List of devices attached
emulator-5554 device

adb cant connect to windows WSA

I am trying to use adb to connect to my Android subsystem in windows (WSA). But when using
adb connect 172.23.178.142 (IP is correct)
This error occurs:

what is the key_code to enable or disable wifi via adb for non rooted device

I have a non rooted Samsung device , i want to enable/disable wi-fi settings for my usages via adb.To open wifi for non rooted device via adb i ran below command
adb -s 4d0075754fdb41cd shell am start -n com.android.settings/.wifi.WifiSettings
By default the wifi is coming as diabled , i want to enable/disable it
I tried with Keyevent , however this did not helped much
adb shell input keyevent 22
The wi-fi slider looks like below , i tried with all available key_code .
Can anyone point me a way to get the correct keycode here!!
You can try adb -s $PHONESERIAL shell "svc wifi enable" if you just want to turn on the wifi with adb.
Was already answered here : android adb turn on wifi via adb
You placed appium tag, so if you using appium, try running:
adb -s $device_id shell am broadcast -a io.appium.settings.wifi --es setstatus enable
adb -s $device_id shell am broadcast -a io.appium.settings.wifi --es setstatus disable

Failed to execute adb -a -P 5037 fork-server server

5037 is not occupied and the error message is reply fd for adb server to client communication not specified. The version of adb is 1.0.39. I want to share port for STF Provider. Appreciate for any help.
As Moon said in his comment: the solution is to run
adb -a -P 5037 daemon
and then
stf provider --adb-host ip -port 5037

Port Redirection not working (80->3306)

i have got a new Linux Server (Debian 6.0) with a Database (MySQL) which is accessed by Port 3306 like as usual.
Now I'd like to access the database due port problems of some users (because port 3306 is often blocked by network firewalls) by port 80 or 443. So the transfer must be redirected from Port 80 to 3306 to keep the Database working.
I have tried following command:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3306
but I got following error:
iptables: No chain/target/match by that name.
Does anyone can help me solve this problem? The NAT table is empty (PREROUTING,POSTROUTING,OUTPUT have no entries) (checked with iptables -t nat -n -L)
In iptables Kernel modules required for NAT functionality:
Run following command to load modules in kernel:
# modprobe iptable_nat
# modprobe ipt_REDIRECT
Make sure you have above modules compiled in kernel:
[root#instructor tmp]# grep REDIRECT /boot/config-$( uname -r )
CONFIG_IP_NF_TARGET_REDIRECT=m
CONFIG_BRIDGE_EBT_REDIRECT=m
In VPS Server:
Enable modules on host server using modprobe command
Execute following command from the host server to enable all the modules for the VPS
vzctl set VEID --iptables iptable_nat --iptables ipt_REDIRECT
Add rules in file /etc/vz/conf/veid.conf
IPTABLES="iptable_nat ipt_REDIRECT"

Resources