Connecting a real device to an Android emulator

I am developing a network application for Android, and I still stick to connecting my real Android device with a device emulator running on my desktop computer.

I created a private network with a router, so the only ones connected to the network are my computer and my mobile phone to avoid problems with the firewall / closed ports.

My pc ip is 192.168.1.100 and I am trying to ping each other so that I can achieve the maritime availability of each node network. Ping works fine from my PC (not the emulator console) on the phone.

The problem is that I want to ping the PC emulator from my mobile phone, not the PC itself ... For this, I use the emulator console ... Do I have to use my computer IP address or use another? I saw an ip like "10.0.xx" here http://developer.android.com/guide/developing/tools/emulator.html

But I assume that they are designed to connect two EMULATORS, right?

In addition, I tried to connect them by socket, creating a port forwarding through the emulator console, but I still can’t connect them.

Any clues? Thank!!

+3
source share
3 answers

, , . , , , redir , .

, - , .

http://www.java2s.com/Code/Java/Network-Protocol/Asimpleproxyserver.htm

:

:

String host = "localhost";
int remoteport = 3000;
int localport = 4000;

:

  • 2000.
  • telnet "redir add tcp: 3000: 2000"

, 4000.

, :

↔ : 4000 -: 3000 ↔ : 3000 : 2000 →

.

+3

, , loopback (127.0.0.1), , "redir add tcp: port: newPort", ( loopback) ( " ip" ).

, , , IP 127.0.0.1, . , , ...

, -, , .

0

, .

Did you try to configure redirection on the emulated device, and then connect the real device through a java socket?

For instance:

On the emulated device, open the server socket listening on port 2000, then open the telnet connection and run the command:

redir add tcp: 4000: 2000

Finally, open the socket on the real device to your machine address (192.168.1.100) on port 4000.

0
source

Source: https://habr.com/ru/post/1770780/


All Articles