The Android system only accesses the PC by default via IP (10.0.2.2), and the PC does not have direct access to the Android emulator system via IP. To achieve communication between PC and Android simulator system and Android Simulator, it is necessary to use port redirection (redir).
Let's talk about the Telnet client installation required for Port redirection:
Windows:
Install the Telnet client. If it is not installed, you can enable the Telnet client feature by locating the Telnet client menu item under open or close system functionality in Windows Program management.
Linux:
Install the Telnet client yourself.
The reason why PC computer can't directly access the Android simulator system
The Android system sets the PC IP to 10.0.2.2 for communication and 10.0.2.15/127.0.0.1. However, the PC does not specify an IP for the Android emulator system, so the PC can only communicate with the Android emulator via port redirection.
Ii. communication between PC and Android simulator systems
1. Running the simulator
2. Open the window command line and execute:
5554 is the port of the simulator (located in the title bar of the Android Emulator window) and will enter the Android console after execution
3, under the console execution:
1 2 3 |
Format: Redir add < udp/tcp ;:< PC port ;:< emulator port > Example: Redir add udp:2888:2888 Redir Add tcp:2888:2888 |
After executing this command, the TCP/UDP data received by the PC 2888 port is transferred to port 2888 of the simulator.
Iii. communication between multiple Android simulator systems
1. Start the simulator emulator-5554 and emulator-5556
2. Open DOS window to perform telnet localhost 5554 connection to simulator 5554
3. After successful connection, continue execution: Redir add tcp:5000:6000 binds the PC port 5000 to port 6000 on simulator 5554.
4. The simulator 5556 communicates with the simulator 5554 by sending the TCP/UDP packet to the PC port 5000 (i.e. address: 10.0.2.2:5000).
5, the same as the Step 2, the implementation of the PC computer to the simulator 5556 port forwarding.
Once added, we can use the redir List command to list the mapped ports that have been added, redir del can be deleted.
TCP/UDP communication between PC and Android simulator access and simulator