adb forward remote port to local machine

会有一股神秘感。 提交于 2020-01-28 14:11:37

问题


This is a query regarding the usage of adb on android.

Is there a way to forward the remote port i.e. port on the android device/emulator to the local machine to which the device is connected?

$ adb forward tcp:port1 tcp:port2 # forwards the local port port1 on the machine to port2 on the device.

Thanks in advance!


回答1:


Recently google updated ADB service. And added reverse command that should do the job.

From reverse documentation:

This implements the adb reverse feature, i.e. the ability to reverse socket connections from a device to the host. <forward-command> is one of the forwarding commands that are described above, as in:

  1. list-forward
  2. forward:<local>;<remote>
  3. forward:norebind:<local>;<remote>
  4. killforward-all
  5. killforward:<local>

Note that in this case, <local> corresponds to the socket on the device and <remote> corresponds to the socket on the host.

The output of reverse:list-forward is the same as host:list-forward except that <serial> will be just host.




回答2:


Do you truly need to forward the port or are you just looking for a way to communicate using sockets from a program running on the android shell to your host machine? I was able to accomplish the latter by sending my message to the port of interest on "10.0.2.2", which is the loopback adapter of the host machine. See docs here.

EDIT
This is the updated link



来源:https://stackoverflow.com/questions/3415797/adb-forward-remote-port-to-local-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!