6

According to Android Debug Bridge :

The server then sets up connections to all running emulator/device instances. It locates emulator/device instances by scanning odd-numbered ports in the range 5555 to 5585, the range used by emulators/devices. Where the server finds an adb daemon, it sets up a connection to that port. Note that each emulator/device instance acquires a pair of sequential ports — an even-numbered port for console connections and an odd-numbered port for adb connections. For example:

Emulator 1, console: 5554

Emulator 1, adb: 5555

Emulator 2, console: 5556

Emulator 2, adb: 5557 ...

The ADB server only checks for devices by scanning odd-numbered ports in the range 5555 to 5585 ( 30 ports in total) and assigns 2 ports for each device. Is ADB capable of accepting more than 15 Android Devices (15x2 ports) or can I connect more devices on the same computer? I think it is impossible to run more than one ADB servers on the same machine.

Community
  • 1
  • 1
glarkou
  • 7,023
  • 12
  • 68
  • 118
  • If adb service runs at port 5037 then why does it locate devices in the range 5555 to 5585 ? – Shivam Aggarwal Dec 03 '15 at 16:05
  • because it needs a persistent connection for every device, thus a port for every device – glarkou Dec 04 '15 at 07:39
  • can you please give me some examples of adb clients and what adb clients really are. I used to think that the devices that I connect to my machine i.e phone/emulator are clients but instead they are adb devices. – Shivam Aggarwal Dec 06 '15 at 13:34

2 Answers2

7

Max number of ports used by adb can be changed by setting ADB_LOCAL_TRANSPORT_MAX_PORT environment variable. You can simply take a look on the adb code (it's opensource because it's part of Android). You can see that max number of adb ports is set like this:

static int adb_local_transport_max_port = DEFAULT_ADB_LOCAL_TRANSPORT_PORT + 16 * 2 - 1;

where DEFAULT_ADB_LOCAL_TRANSPORT_PORT is 5555. Each device requires 2 ports (console connection + adb connection). So use this formula to calculate your max port: max_port = 5555 + 2 * N + 1

Read here how to set environment variable on Windows. And for Linux/macOS it can be done by simply editing .bash_profile (or .profile) file in your home directory. So there's actually no need in additional adb servers like Ashley suggests in another answer.

alexal1
  • 394
  • 3
  • 7
4

You can run more than one instance of adb on the same computer using the environment variable ANDROID_ADB_SERVER_PORT. see more details on this answer.

With the -ports option on the emulator, you can specify any port, and then do:

$ adb connect localhost:PORT

If your phone is rooted you can restart adbd on another port (see another answer), and then:

$ adb connect IP_OF_DEVICE:PORT

The device is then available over wifi and does not need to be plugged in. Be aware that anyone on your wifi network can access your phone this way!

Community
  • 1
  • 1
ashley willis
  • 1,601
  • 1
  • 13
  • 10
  • Is it possible to access a not rooted device over wifi? – glarkou Jun 02 '12 at 20:04
  • No, the device must be rooted, and you must change the settings from a root prompt on the device, or `adb shell` must give you a root prompt (my phone usually does not, though it has `su` installed). I don't know how to get back to USB when `adb shell` does not give a root prompt, short of rebooting. – ashley willis Jun 02 '12 at 21:46
  • 4
    Yes, you can do ADB over wifi with non-rooted devices. See http://stackoverflow.com/questions/2604727/how-can-i-connect-to-android-with-adb-over-tcp – Tom Jan 10 '14 at 00:46