个人理解
forward:端口映射
将本地PC指定Port端口,映射到设备手机指定Port端口上.
以便解决 PC -> Phone 的访问问题
PC 作为Client客户端 可以任意访问 Phone 上的 Server 服务器
参考例子
广域网
启动AirDroid APP - PC通过http://web.airdroid.com访问
同局域网:
启动AirDroid APP - PC直接访问指定局域网网址
不同网段(不同局域网):
启动AirDroid APP - 通过USB连接手机 -
adb forward tcp:8888 tcp:8888
- 在PC上访问 http://127.0.0.1:8888
reverse:反向代理
- Phone 无法访问某个 第三方服务Server服务器
- PC 却可以访问该 第三方服务Server服务器
- Phone -> PC 通过PC来访问 第三方服务Server服务器
参考例子
- 在设备上运行 - React Native 中文网
-
Android Tip: adb reverse | Grio Blog
$ adb reverse tcp:80 tcp:3000 To redirect your phone’s port 80 to your computer’s port 3000.
常用命令
adb forward --list
adb forward --remove-all
adb forward tcp:8888 tcp:8888
http://127.0.0.1:8888/
adb help
connect HOST[:PORT] connect to a device via TCP/IP [default port=5555]
disconnect [HOST[:PORT]]
disconnect from given TCP/IP device [default port=5555], or all
forward --list list all forward socket connections
forward [--no-rebind] LOCAL REMOTE
forward socket connection using:
tcp:<port> (<local> may be "tcp:0" to pick any open port随机绑定本地能正常打开的端口)
localabstract:<unix domain socket name>
localreserved:<unix domain socket name>
localfilesystem:<unix domain socket name>
dev:<character device name>
jdwp:<process pid> (remote only)
forward --remove LOCAL remove specific forward socket connection
forward --remove-all remove all forward socket connections
ppp TTY [PARAMETER...] run PPP over USB
reverse --list list all reverse socket connections from device
reverse [--no-rebind] REMOTE LOCAL
reverse socket connection using:
tcp:<port> (<remote> may be "tcp:0" to pick any open port)
localabstract:<unix domain socket name>
localreserved:<unix domain socket name>
localfilesystem:<unix domain socket name>
reverse --remove REMOTE remove specific reverse socket connection
reverse --remove-all remove all reverse socket connections from device