从 PC 到 Android 模拟器的套接字连接 [英] Socket connection from PC to Android emulator

查看:40
本文介绍了从 PC 到 Android 模拟器的套接字连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这就是我想要做的:我有一个使用 ServerSocket 的 Android 应用程序,我需要从我的计算机连接到这个套接字.

So here's what I'm trying to do: I have an Android app that uses a ServerSocket and I need to connect to this socket from my computer.

我尝试使用 adb shell ifconfig 获取我的 IP 地址,我可以从模拟器的 shell ping 这个 IP,但我无法从我的计算机终端 ping 它.

I've tried to get my IP address using adb shell ifconfig and I can ping this IP from the emulator's shell but I can't ping it from my computer's terminal.

换句话说,我如何使用 Postman 连接到我的模拟器的网络服务器上?

In other words, how can I use Postman to connect on my emulator's web server?

推荐答案

我找到了解决方案.看来,如果你想从你的计算机到你的模拟器进行通信,要使用的 IP 地址是 127.0.0.1 并且你需要在命令行中使用 ADB 进行一些端口转发.

I've found the solution. It seems that if you want to communicate from your computer to your emulator, the IP address to use is 127.0.0.1 and you need to do some port forwarding using ADB in command line.

例如,如果您的模拟器在端口 8080

For example if you emulator is running a server on port 8080

adb 转发 tcp:8080 tcp:8080

然后用 localhost:8080

这篇关于从 PC 到 Android 模拟器的套接字连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆