如何将本地主机 IP 地址转发到 Android 模拟器?

发布于 2024-10-18 12:09:41 字数 136 浏览 5 评论 0原文

我知道可以将端口从我的开发机器转发到 Android 模拟器,但是这是如何完成的呢? 我在 android-developers 网站上找到了解决方案,但我不明白他们的说明是什么意思...... 有人对此有明确的指示吗?我的开发机器运行的是 Windows。

I know it is possible to forward a port from my develop machine to an Android emulator, but how is this done?
I've found the solution on the android-developers site, but I couldn't see how they've meant their instructions...
Anybody got some clear instructions on this? My develop machine is running Windows.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

缪败 2024-10-25 12:09:41

要将端口从本地计算机转发到 Android 模拟器,您需要启用 Telnet。这是通过“控制面板”->“控制面板”来完成的。程序和功能 ->打开或关闭 Windows 功能 ->向下滚动到 Telnet 客户端。然后选择它&按“确定”。现在,从命令提示符(运行模拟器)中输入 telnet localhost "EmulatorPortNumber"。 “EmulatorPortNumber”可以在模拟器的标题栏中找到,在我的例子中是 5554。

您现在将看到与此类似的内容:

Android Console: type 'help' for a list of commands
OK

在这里,您希望输入尽可能少的拼写错误,就像应用退格键时一样,它会破坏你的命令并且不接受它。您必须在此处使用的命令是redir。这将让您从 3 个子命令中进行选择:

list    list current directions
add     add new redirection
del     remove existing redirection

您现在需要的一个是 add。但你不能就这样使用它。输入 redir add 将显示以下行:

KO: bad redirection format, try (tcp|udp):hostport:guestport

这意味着您必须指定要转发的端口类型(TCP 或 UDP 端口)、要转发的本地计算机上的哪个端口(主机端口)和您要在模拟器上设置哪个端口(来宾端口)。
因此,使用这样的命令:

redir add udp:1337:12345

将本地计算机上的 UDP 端口 1337 转发到模拟器上的端口 12345。删除重定向时要小心,因为它们可能会使您的模拟器崩溃。您还可以简单地关闭模拟器来删除任何重定向。这更容易&更安全...

To forward a port from your local machine to an Android Emulator, you need to have Telnet enabled. This is done through the Control Panel -> Programs and Features -> Turn Windows features on or off -> scroll down to Telnet Client. Then select it & press Ok. Now from your command prompt (with the Emulator running) you type telnet localhost "EmulatorPortNumber". The "EmulatorPortNumber" can be found in the titlebar of the Emulator, in my case it was 5554.

You will now see something similar to this:

Android Console: type 'help' for a list of commands
OK

Here, you want to type with as little as possible typo's, as when you apply the backspace, it will corrupt your command and not accept it. The command you have to use here is redir. This will let you choose from 3 subcommands:

list    list current directions
add     add new redirection
del     remove existing redirection

The one you need now is add. But you can't use it just like that. Typing redir add will give you the following line:

KO: bad redirection format, try (tcp|udp):hostport:guestport

This means that you have to specify what kind of port you want to forward (TCP or UDP port), which port on the local machine you want to forward (hostport) & which port you want to set on the Emulator (guestport).
So, using a command like this:

redir add udp:1337:12345

forwards the UDP port 1337 on the local machine to port 12345 on the Emulator. Be cautious about deleting redirections, as they might crash your Emulator. You can also simply close the Emulator to remove any redirections. It's easier & safer...

爱殇璃 2024-10-25 12:09:41

您从模拟器中以 10.0.2.2 身份访问计算机的 localhost。更多详细信息此处

You access your computer's localhost as 10.0.2.2 from emulator. more details here

回梦 2024-10-25 12:09:41

您可以使用 adbforward 命令设置任意端口转发 - 将特定主机端口上的请求转发到模拟器/设备实例上的不同端口。以下是如何设置主机端口 6100 到模拟器/设备端口 7100 的转发:

adb forward tcp:6100 tcp:7100

例如,在 AVD 上运行 NanoHTTPD Web 服务器,然后在计算机上执行此命令:

adb forward tcp:8080 tcp:8080

打开浏览器计算机并导航以下地址:

localhost:8080

http://developer.android .com/tools/help/adb.html#forwardports

You can use the adb forward command to set up arbitrary port forwarding — forwarding of requests on a specific host port to a different port on an emulator/device instance. Here's how you would set up forwarding of host port 6100 to emulator/device port 7100:

adb forward tcp:6100 tcp:7100

For example run NanoHTTPD web server on the AVD and then execute this command on the computer:

adb forward tcp:8080 tcp:8080

Open the browser on the computer and navigate the below address:

localhost:8080

http://developer.android.com/tools/help/adb.html#forwardports

み零 2024-10-25 12:09:41

使用最新版本的 Android 模拟器(在 Android Studio 2021.1 中),它在我的开发机器上以非常简单的方式工作

  • 我在 Chrome(开发机器)上的 http://localhost:8080 上启动了一个服务
  • 我转到:chrome:// spect/#devices
  • 端口转发
  • 在我的 Android 模拟器上自动启动 我只需导航到:http://localhost:8080 就可以访问开发计算机上的网站

Using latest version of Android Emulator (in Android Studio 2021.1) it works in a very simple way

  • on my dev machine I start a service on http://localhost:8080
  • on my Chrome (dev machine) I go to: chrome://inspect/#devices
  • the port forward starts automatically
  • on my Android Emulator I can reach the website on the dev machine just navigating to: http://localhost:8080
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文