#How to connect multiple Android devices with ADB over TCP
According to a post on xda-developers, you can enable ADB over Wi-Fi from the device with the commands:
su
setprop service.adb.tcp.port 5555
stop adbd
start adbd
And you can disable it and return ADB to listening on USB with
setprop service.adb.tcp.port -1
stop adbd
start adbd
Open terminal and install adb using
sudo apt-get install android-tools-adb android-tools-fastboot
Connect your phone via USB cable to the PC. Type following command in terminal to get the device ID:
$ adb devices
List of devices attached
LGV498b9cacc1 device
192.168.1.187:5558 device
192.168.1.184:5557 device
192.168.1.186:5556 device
192.168.1.143:5555 device
Using the device name listed above, get the IP of your Android device (if you know you can skip this step)
$ adb -s LGV498b9cacc1 shell ip -f inet addr show wlan0
22: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
inet 192.168.1.185/24 brd 192.168.1.255 scope global wlan0
Setup the communication port using this command:
$ adb -s LGV498b9cacc1 tcpip 5559
restarting in TCP mode port: 5559
Connect to your Android device IP address.
$ adb -s LGV498b9cacc1 connect 192.168.1.185:5559
connected to 192.168.1.185:5559
Verify if the device was added to the list:
$ adb devices
List of devices attached
192.168.1.185:5559 device
LGV498b9cacc1 device
192.168.1.187:5558 device
192.168.1.184:5557 device
192.168.1.186:5556 device
192.168.1.143:5555 device
Now you can remove your phone.
Enable Developer options in your Android phone using this way.
- Open Settings> About> Software Information> More.
- Then tap “Build number” seven times to enable Developer options.
- Go back to Settings menu and now you'll be able to see “Developer options” there.
- Tap it and turn on USB Debugging from the menu on the next screen.
Open your cmd and type adb. If you find that the adb is not a valid command then you have to add a path to the environment variable.
- First go to you SDK installed folder. Follow this path as an example. ```` D:\softwares\Development\Andoird\SDK\sdk\platform-tools; D:\softwares\Development\Andoird\SDK\sdk\tools; ```
- Now search on windows system advanced setting
- Open the Environment variable.
- Then open the "PATH" variable and paste the previous example path to its variable value.
- NOTE: You SDK path is different from mine please use yours. Now you can connect your android phone to PC.
Connect your phone via USB cable to the PC. Open cmd and type following command in terminal to get the device ID:
$ adb devices
List of devices attached
LGV498b9cacc1 device
192.168.1.187:5558 device
192.168.1.184:5557 device
192.168.1.186:5556 device
192.168.1.143:5555 device
Using the device name listed above, get the IP of your Android device (if you know you can skip this step)
$ adb -s LGV498b9cacc1 shell ip -f inet addr show wlan0
22: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
inet 192.168.1.185/24 brd 192.168.1.255 scope global wlan0
Setup the communication port using this command:
$ adb -s LGV498b9cacc1 tcpip 5559
restarting in TCP mode port: 5559
Connect to your Android device IP address.
$ adb -s LGV498b9cacc1 connect 192.168.1.185:5559
connected to 192.168.1.185:5559
Verify if the device was added to the list:
$ adb devices
List of devices attached
192.168.1.185:5559 device
LGV498b9cacc1 device
192.168.1.187:5558 device
192.168.1.184:5557 device
192.168.1.186:5556 device
192.168.1.143:5555 device
Now you can remove your device and run your Android project.
First of all thanks for the tutorial. I have one query regarding port forwarding. Hope you help me.
I am doing client server communication through Socket over USB. For server side, I created one Java sample which is waiting for user to connect with specific port (38500). Server side project is running on PC. Now for client side, I created one application in Android. In that Client create Socket to connect "localhost" on specific port (38400).
Procedure to Execute:
adb reverse tcp:38400 tcp:38500
At this point, all is working fine for 1 server to 1 client.
Issue is that, when I connect two devices (through USB) then it shows me like below output.
adb reverse tcp:38400 tcp:38500
error: more than one device/emulator
But when I do like,
adb -s ZY2235KL8Z -s ZY2238JL7F reverse tcp:38400 tcp:38500
It works fine and no error displayed. But my server only recognize only one device "ZY2238JL7F" i.e last device name enter after -s.
Should I achieve "One server multiple Client(Android Devices) through USB" from abd commands?
Thanks in Advance!