android adb 端口转发

本文介绍了Android Debug Bridge(adb)的端口转发功能,允许将数据从本地端口转发到模拟器或设备实例的监听端口。adb是一个管理Android模拟器或设备状态的工具,包括端口转发、文件传输、shell命令等功能。通过adb forward命令,可以实现TCP端口的转发,例如将本地的55555端口转发到模拟器的5556端口。此外,文章还详细说明了如何查询和控制连接到adb服务器的设备实例,以及adb的各种其他用途。
摘要由CSDN通过智能技术生成

之前,以为android模拟器只能作为client来对待,不能创建socket server来接收数据,原因是用tcpview看了一下,创建的监听端口,并没有显示,

所以,后来,就打算用vc直接开发一个daemon程序来接收请求,同时转发请求。


当apkserver完成后,发现adb命令支持端口转发功能,这才醒悟过来,白忙活了,不过,自己搞一个daemon还是可以的。

下面就是官方对adb的介绍,可以看看adb forward tcp:55555 tcp:5556命令。把发往本地监听55555端口的数据转发到模拟器里的监听端口5556.


adb来自官网的简介-Android Debug Bridge


Android Debug Bridge

ADB quickview

  • Manage the state of an emulator or device
  • Run shell commands on a device
  • Manage port forwarding on an emulator or device
  • Copy files to/from an emulator or device

In this document

  1. Issuing ADB Commands
  2. Querying for Emulator/Device Instances
  3. Directing Commands to a Specific Emulator/Device Instance
  4. Installing an Application
  5. Forwarding Ports
  6. Copying Files to or from an Emulator/Device Instance
  7. Listing of adb Commands
  8. Issuing Shell Commands
  9. Enabling logcat Logging
  10. Stopping the adb Server

See also

  1. Emulator

Android Debug Bridge (adb) is a versatile tool lets you manage thestate of an emulator instance or Android-powered device. It is aclient-server program that includes three components:

  • A client, which runs on your development machine. You caninvoke a client from a shell by issuing an adb command. Other Androidtools such as the ADT plugin and DDMS also create adb clients.
  • Aserver, which runs as a background process on your development machine.The server manages communication between the client and the adb daemonrunning on an emulator or device.
  • A daemon, which runs as a background process on each emulator or device instance.

When you start an adb client, the client first checks whether thereis an adb server process already running. If there isn't, it starts theserver process. When the server starts, it binds to local TCP port 5037and listens for commands sent from adb clients—all adb clients use port5037 to communicate with the adb server.

The server then sets up connections to all running emulator/deviceinstances. It locates emulator/device instances by scanningodd-numbered ports in the range 5555 to 5585, the range used byemulators/devices. Where the server finds an adb daemon, it sets up aconnection to that port. Note that each emulator/device instanceacquires a pair of sequential ports — an even-numbered port for consoleconnections and an odd-numbered port for adb connections. For example:

Emulator 1, console: 5554
Emulator 1, adb: 5555
Emulator 2, console: 5556
Emulator 2, adb: 5557 ...

As shown, the emulator instance connected to adb on port 5555 is the same as the instance whose console listens on port 5554.

Once the server has set up connections to all emulator instances,you can use adb commands to control and access those instances. Becausethe server manages connections to emulator/device instances and handlescommands from multiple adb clients, you can control any emulator/deviceinstance from any client (or from a script).

The sections below describe the commands that you can use to accessadb capabilities and manage the state of an emulator/device. Note thatif you are developing Android applications in Eclipse and haveinstalled the ADT plugin, you do not need to access adb from thecommand line. The ADT plugin provides a trasparent integration of adbinto the Eclipse IDE. However, you can still use adb directly asnecessary, such as for debugging.

Issuing adb Commands

You can issue adb commands from a command line on your development machine or from a script. The usage is:

adb [-d|-e|-s <serialNumber>] <command> 

When you issue a command, the program invokes an adb client. Theclient is not specifically associated with any emulator instance, so ifmultiple emulators/devices are running, you need to use the-doption to specify the target instance to which the command should bedirected. For more information about using this option, seeDirecting Commands to a Specific Emulator/Device Instance.

Querying for Emulator/Device Instances

Before issuing adb commands, it is helpful to know whatemulator/device instances are connected to the adb server. You cangenerate a list of attached emulators/devices using thedevices command:

adb devices

In response, adb prints this status information for each instance:

  • Serial number — A string created by adb to uniquely identify an emulator/device instance by its console port number. The format of the serial number is<type>-<consolePort>. Here's an example serial number:emulator-5554
  • Sta
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

winsunxu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值