Connecting 2 Emulator Instances in Android

how to connect two emulator instances on the same machine and transfer data(a file) between them?

How to communicate between two Android emulators is explained in http://developer.android.com/guide/developing/devices/emulator.html:

Interconnecting Emulator Instances

To allow one emulator instance to communicate with another, you must
set up the necessary network redirections as illustrated below.

Assume that your environment is

  • A is you development machine
  • B is your first emulator instance, running on A
  • C is your second emulator instance, running on A too

and you want to run a server on B, to which C will connect, here is how
you could set it up:

  1. Set up the server on B, listening to 10.0.2.15:
  2. On B's
    console, set up a redirection from A:localhost: to
    B:10.0.2.15:
  3. On C, have the client connect to
    10.0.2.2:

For example, if you wanted to run an HTTP server, you can select as 80 and as 8080:

  • B listens on 10.0.2.15:80
  • On B's console, issue redir add tcp:8080:80
  • C connects to 10.0.2.2:8080

Hope it helps!

Can I open 2nd emulator concurrently in android studio

You have to have emulators created, after that just run and build the app on the desired device. its okay.

Communication between two Android emulators

What you need is to install TELNET on your Windows 7 machine. For that, Control Panel -> Programs and Features -> Turn Windows Features On or Off -> Telnet Client (must be ticked).

Then, in cmd (command prompt), you can say adb devices (if the Android SDK is on your PATH), which returns identifiers such as emulator-5554 and emulator-5556.

Now with telnet, you can access them with telnet localhost 5554 or telnet localhost 5556.

initial connection

To get them to tell you which emulator it is, you can type avd name.

But more importantly, it tells you this:

Android Console: Authentication required
Android Console: type 'auth <auth_token>' to authenticate
Android Console: you can find your <auth_token> in
'C:\Users\[youruser]\.emulator_console_auth_token'
OK

Which is a text file that contains some random cryptic text.

You can copy paste that into the telnet like so:

auth cdPi82HewjZg

to which it will say OK, now you can actually run the command the documentation said.

after auth

Now you can say

redir add tcp:6000:4000

Which means: if the emulator would receive something to Port 6000 from LocalHost, then it should receive it as 4000

Which means your other emulator can connect to it through the 10.0.2.2 magic loopback IP by sending data to 6000, and it is the other emulator that will receive it, with port 4000.

no session yet

joined session

It also works not just for tcp: but also for udp:.

You can list redir and even remove redirections with redir del.



Related Topics



Leave a reply



Submit