foreword
When adb is connected to a mobile phone, the offline situation often occurs. Generally, killing adb and restarting adb can solve it.
If you find that no matter how you restart adb, you can't connect to it, and there is always an offlie situation. At this time, it is very likely that port 5037 of adb is occupied by other applications.
offline
1. If you have been able to connect to adb normally before, but suddenly cannot connect, you can use adb devices to check the connection status of the mobile phone
C:\Users\admin>adb devices
List of devices attached
* daemon not running; starting now at tcp:5037
* daemon started successfully
emulator-5554 offline
C:\Users\admin>adb devices
List of devices attached
emulator-5554 offline
2. It is found that it cannot be connected, and offline appears. You can try adb kill-server, and then use adb device to view
C:\Users\admin>adb kill-server
C:\Users\admin>adb devices
List of devices attached
* daemon not running; starting now at tcp:5037
* daemon started successfully
emulator-5554 offline
3. The above methods have been tried, but they cannot be solved. Next, we will check port 5037.
view port
1. On windows, you can use findstr to filter processes (similar to the grep command on linux), and the query result looks at the last PID. If it is 0, don't care, then there are two PIDs occupying port 5037 at the end,
namely 6532 and 6532 . 7200
netstat -aon|findstr 5037
C:\Users\admin>netstat -aon|findstr 5037
TCP 127.0.0.1:5037 0.0.0.0:0 LISTENING 6532
TCP 127.0.0.1:5037 127.0.0.1:56975 TIME_WAIT 0
TCP 127.0.0.1:5037 127.0.0.1:56976 TIME_WAIT 0
TCP 127.0.0.1:5037 127.0.0.1:56981 ESTABLISHED 6532
TCP 127.0.0.1:5037 127.0.0.1:56988 TIME_WAIT 0
TCP 127.0.0.1:5037 127.0.0.1:56990 TIME_WAIT 0
TCP 127.0.0.1:5037 127.0.0.1:56991 TIME_WAIT 0
TCP 127.0.0.1:56981 127.0.0.1:5037 ESTABLISHED 7200
2. Next, check the PID to see which application occupies
tasklist /fi "PID eq port number"
C:\Users\admin>tasklist /fi "PID eq 6532"
映像名称 PID 会话名 会话# 内存使用
========================= ======== ================ =========== ============
adb.exe 6532 Console 1 18,432 K
C:\Users\admin>tasklist /fi "PID eq 7200"
映像名称 PID 会话名 会话# 内存使用
========================= ======== ================ =========== ============
emulator-arm.exe 7200 Console 1 884,088 K
3. It can be seen from the results that there are two applications occupied, one is adb itself, and the other is the emulator (emulator-arm.exe), the port conflicts, and then kill the process occupying port 5037
taskkill /pid 7200 /f
C:\Users\admin>taskkill /pid 7200
成功: 已终止 PID 为 7200 的进程。