开发者

Communication between two Android emulators

My machine is running on window 7. I want to communicate between two android emulator's running on same machine.

Emulator first is listening on some IP 10.0.2.15 When second emulator tries to create

Socket socket = new Socket ("10.0.2.15",8080);

It gives exception, unable to connect to 10.0.2.15 does any one know how to solve this problem?

EDIT: I've already read https://developer.android.com/studio/run/emulator-networking#connecting but it says

On B's console, issue redir add tcp:8080:80

What 开发者_如何学Pythondoes it mean by B's console, or where is B's console??


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.

Communication between two Android emulators

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.

Communication between two Android emulators

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.

Communication between two Android emulators

Communication between two Android emulators

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

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


There may be two reasons

  1. As per my knowledge is concerned you have run is < 2.3 version
  2. Add Internet permission
  3. Try to run the server first say in emulator number 5554 and client (say) 5556
    then type

    telnet localhost 5554
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜