Android adb 将远程端口转发到本地机器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3415797/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
adb forward remote port to local machine
提问by Gaurav Khurana
This is a query regarding the usage of adb on android.
这是一个关于在android上使用adb的查询。
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?
有没有办法将android设备/模拟器上的远程端口即端口转发到设备所连接的本地机器?
$ adb forward tcp:port1 tcp:port2 # forwards the local port port1 on the machine to port2 on the device.
$ adb forward tcp:port1 tcp:port2 # 将机器上的本地端口port1 转发到设备上的port2。
Thanks in advance!
提前致谢!
回答by molokoka
Recently google updated ADB service. And added reverse
command that should do the job.
最近谷歌更新了亚行服务。并添加reverse
了应该完成这项工作的命令。
From reversedocumentation:
从反向文档:
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:
list-forward
forward:<local>;<remote>
forward:norebind:<local>;<remote>
killforward-all
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 justhost
.
这实现了该
adb reverse
功能,即反向从设备到主机的套接字连接的能力。<forward-command>
是上面描述的转发命令之一,如:
list-forward
forward:<local>;<remote>
forward:norebind:<local>;<remote>
killforward-all
killforward:<local>
注意,在这种情况下,
<local>
对应于设备<remote>
上的套接字,对应于主机上的套接字。的输出
reverse:list-forward
与 host:list-forward 相同,<serial>
只是host
.
回答by RickNotFred
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.
您是否真的需要转发端口,或者您只是在寻找一种使用套接字从运行在 android shell 上的程序到您的主机的通信方式?我能够通过将我的消息发送到“10.0.2.2”上感兴趣的端口来完成后者,这是主机的环回适配器。请参阅此处的文档。
EDIT
This is the updated link
编辑
这是更新的链接