【问题标题】:How to connect to socket server inside emulator from ubuntu?如何从 ubuntu 连接到模拟器内的套接字服务器?
【发布时间】:2022-01-06 14:37:27
【问题描述】:

我使用 android studio (jetbrains) 开发应用程序。

我尝试运行套接字服务器,这是代码的一部分:

ServerSocket ss = new ServerSocket(9002);
Socket s = ss.accept();

没有错误,看起来服务器正在运行。我使用来自 android-studio 的模拟器,我使用工作室用户界面中的绿色按钮运行它..

但是当我在 ubuntu 终端中扫描打开的端口时 - 没有 9002 端口。并且无法在模拟器之外连接到它...

防火墙处于非活动状态..

怎么做?

【问题讨论】:

    标签: android-studio


    【解决方案1】:

    我必须设置从操作系统级别到模拟器的端口重定向。

    首先需要连接模拟器:

    telnet localhost 5554
    

    5554 - 是一个模拟器端口,运行模拟器时会在控制台打印出来。

    那么你可能需要进行身份验证,这里解释了Android terminal--telnet missing commands, receiving this error : KO: unknown command, try 'help'

    然后你设置重定向:

    redir add tcp:5000:9002
    

    官方文档在这里https://developer.android.com/studio/run/emulator-networking?hl=it

    【讨论】:

      猜你喜欢
      • 2017-06-24
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-25
      • 2019-12-10
      • 1970-01-01
      相关资源
      最近更新 更多