Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
527 views
in Technique[技术] by (71.8m points)

emulation - Android emulator access redir port from other host

Have a server-socket running in an android application, which I debug using the emulator. Using the emulators console and "redir add tcp:8888:8888" I can make the service available to a program running on my development machine (as localhost:8888).

The redir port is however not available on any other network interface, meaning I can't access it through the host-ip on either the local development machine, or from a secondary machine on the network. Anyone know if its possible to make the emulator bind to all network interfaces, or have some other trick to enable other hosts on the network to connect to the emulator?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I found the OP's comment/suggestion of using rinetd to be much easier than iptables.

rinetd can intercept connections on one interface and forward them to a different IP; so, to solve this problem of the emulator not being accessible to computers other than the host machine, you intercept the incoming connections to your host and forward them to 127.0.0.1

Here's how:

First, install rinetd (http://www.boutell.com/rinetd/)

  • Linux: either download it from the link above, or, in a terminal in Ubuntu, enter "sudo apt-get install rinetd". The command could be different in other Linux distros...
  • Windows: download from the link above (but it only says 95/98/NT..)

Next, set up a port redirection in the emulator:

  • start your AVD
  • in a terminal, enter "telnet localhost 5554" (or whatever the port for your avd is)
  • once connected by telnet, enter "redir add <protocol>:<host port>:<emu port>" (e.g., "redir add tcp:5000:7000" to forward tcp data sent to port 5000 on the host to port 7000 in the emulator)

Configure rinetd:

  • Edit the file /etc/rinetd.conf and add the line "<host ip> <host port> 127.0.0.1 <localhost port>". So if your host computer's IP address is 123.45.67.89 and you want to use port 5000 and then forward it to 127.0.0.1:5000, "123.45.67.89 5000 127.0.0.1 5000"

I'm not sure if rinetd is launched automatically after you install it.. to run it:

  • "/usr/sbin/rinetd"

To re-initialize rinetd after modifying the config file:

  • "cat /var/run/rinetd.pid" shows you the pid of rinetd
  • "sudo kill -1 <pid>" re-initializes it (e.g, "sudo kill -1 3225")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...