0

I am connecting wireless over TCP to a rooted samsung android device via ADB. By following instructions in this.

Everything seems just fine but it seems that sometimes Android Studio cannot connect by the port 5555 so it changes it to 5037.

Which causes the connection to get refused, so when I try to connect using adb connect 192.168.2.109:5555 , I get:

* daemon not running. starting it now on port 5037 *
* daemon started successfully *
unable to connect to 192.168.2.109:5555: Connection refused

Solution of this problem: I have changed TCP port in my android device to be 5037 and it works perfectly

My Question is: why is the TCP port in Android Studio changing?

Information: OS: Ubuntu 18.04.1 LTS, Android Studio: 3.1.4

Bakri Bitar
  • 1,543
  • 18
  • 29

1 Answers1

2

Everything seems just fine but it seems that sometimes Android Studio cannot connect by the port 5555 so it changes it to 5037.

This is not what is really happening here. Your understanding of the process is completely wrong.

There are 3 parts of adb:

  • adbd daemon, which runs as a background process in every device or emulator instance.
  • adb server, which runs as a background process on your development machine. The server handles multiplexing and manages overall communications between the adb client and the adb daemon.
  • adb client (same binary as adb server), which also runs on your development machine.

adb tcpip <PORT> command changes config of the adbd daemon on the device. adb connect <IP>:<PORT> command tells the adb server to connect to the remote adbd daemon process over TCPIP network instead of default USB connection.

And finally * daemon not running. starting it now on port 5037 * message refers to local adb server instance being started. Port 5037 is used for communication between adb client and adb server and it has nothing to do with the port specified by adb tcpip or adb connect commands.

So your why is the TCP port in Android Studio changing? question has no answer because Android Studio is not changing anything. From unable to connect to 192.168.2.109:5555 you can see that it indeed is trying to use the 5555 port as directed.

Alex P.
  • 30,437
  • 17
  • 118
  • 169
  • Thanks for your detailed answer, Alex, but it doesn't explain why connection successes when I change port to 5037 in the android device – Bakri Bitar Sep 14 '18 at 10:02
  • I did not think it needed extra explaining. You can select any arbitrary port (as long it is not taken already) for your `adb tcpip` command and then use it (the same port number) in your `adb connect` command and it is going to work. `5555` is just a default value to be used when the port part is omitted. The point I was trying to get across in my answer was that you choosing `5037` bears no significance. You were not *required* to use that specific value to make things work. – Alex P. Sep 14 '18 at 15:17
  • I ask adb to connect using port 5555 (which is explicitly set as port in adbd daemon) but instead, adb uses 5037. That's why I needed to change the port in adbd to 5037 to get it working – Bakri Bitar Sep 14 '18 at 15:37
  • well I know what I am talking about and it seems you are still confused. so keep reading my answer until it starts making sense to you. I promise - it eventually will – Alex P. Sep 14 '18 at 15:45
  • I got it. Then I have to investigate why I cannot use the port 5555 for communication and connection gets refused :) – Bakri Bitar Sep 14 '18 at 19:46