Search code examples
androidandroid-studiotcpadb

ADB TCP port automatically changes to 5037


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


Solution

  • 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.