We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
GuidesCoding and DebuggingRunning Your App on the EmulatorUsing the EmulatorAccessing the Network Using the Emulator

Accessing the Network Using the Emulator

Accessing the Internet

Emulators can access the Internet through the network of the local computer.

The emulator leverages the local computer's Ethernet or WLAN connection, sharing the same network resources. If the network connection fails, check whether local network access is restricted (for example, on a corporate intranet). If network access is restricted, configure a network proxy on the emulator by following the instructions in Network.

If a digital certificate is required to access the network, install the digital certificate by following the instructions in How do I install a digital certificate for initiating HTTPS requests.

NOTE

Since the emulator's virtual Ethernet remains in a connected state, disconnecting the local computer's network or the Wi-Fi within the emulator will not put the emulator into a fully disconnected network state.

Since version 26.0.0, network disconnection simulation is supported.

Accessing the Local Network

Create a network server on the local computer. The emulator can access the server on the local computer through 10.0.2.2:<localPort>. 10.0.2.2 is the default gateway of the emulator.

Enabling Mutual Access Between Two Emulators

If two emulators need to communicate with each other, perform the following steps:

  1. Run emulators A and B on the local computer. The device IP address of the emulator is 10.0.2.15.
  2. On emulator B, set the server to listen for 10.0.2.15:<serverPort>.
  3. On the local computer, set redirection from the local computer (localhost:<localPort>) to emulator B (10.0.2.15:<serverPort>). For example:
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. hdc -t 127.0.0.1:5555 fport tcp:<localPort> tcp:<serverPort>

    127.0.0.1:5555 is the HDC service port number of emulator B, which can be queried using the hdc list targets command.

  4. On emulator A, set the client to connect to 10.0.2.2:<localPort>. 10.0.2.2 indicates the default gateway of the emulator.

Network Disconnection Simulation

Since version 26.0.0, the emulator supports network disconnection simulation. After launching the emulator, swipe down to open the control center and enable airplane mode to simulate network disconnection and debug app behaviors under this condition.

Search in Guides
Enter a keyword.