【问题标题】:client server communication app run on emulator but not on device客户端服务器通信应用程序在模拟器上运行,但不在设备上
【发布时间】:2013-03-12 08:25:02
【问题描述】:

我正在为 android 制作客户端服务器应用程序,其中客户端是 android,服务器是本地服务器。 它在模拟器上成功运行,但不在设备上。它实际上并没有崩溃,而是从服务器给出响应

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">
    <title>ERROR: The requested URL could not be retrieved</title>
</head>
<body>
    <div id="content">

    <h1>ERROR</h1>
    <h2>The requested URL could not be retrieved</h2>
    <hr/>
    <P>
     While trying to retrieve the URL:
    <A HREF="http://10.0.2.2/test/testing.php">http://10.0.2.2/test/testing.php</A>
    <P>
     The following error was encountered:
   <UL>
       <LI>
            <STRONG>
         Connection to 10.0.2.2 Failed
         </STRONG>
     </UL>
         <P>
     The system returned:
     <PRE><I>    (110) Connection timed out</I></PRE>
         <P>
         The remote host or network may be down.  Please try the request again.
            <P>Your cache administrator is <A HREF="mailto:webmaster">webmaster</A>. 
     </div>
           <!--
          -- Unfortunately, Microsoft has added a clever new
          -- feature to Internet Explorer.  If the text in
           -- an errors message is too small, specifically
           -- less than 512 bytes, Internet Explorer returns
           -- its own error message.  Yes, you can turn that
           -- off, but *surprise* its pretty tricky to find
          -- buried as a switch called smart error
           -- messages  That means, of course, that many of
           -- Resins error messages are censored by default.
           -- And, of course, youll be shocked to learn that
           -- IIS always returns error messages that are long
           -- enough to make Internet Explorer happy.  The
           -- workaround is pretty simple: pad the error
           -- message with a big comment to push it over the
           -- five hundred and twelve byte minimum.  Of course,
           -- thats exactly what youre reading right now.
         //-->
         </body></html>

我正在使用 httpclient 和 url 是 10.0.2.2 并且还使用互联网权限和 USB 调试。我只想在设备上运行。有没有我必须在移动设备上更改的设置或在 android 清单文件中更改 android 项目或任何想法。

【问题讨论】:

  • 在您的手机浏览器中输入10.0.2.2/test/testing.php,看看是否可以访问。您的手机是连接到同一个网络还是使用 3/4g?
  • 不,一分钟后没有打开,它说“数据连接问题..服务器无法通信。稍后再试”
  • 防火墙已关闭。仍然在说同样的信息。
  • 尝试在您的手机连接到本地网络的情况下打开该 URL。那么你可能会发现问题。
  • 它可以在实时服务器上运行,但我想在本地服务器上运行它.....

标签: android client-server httpclient


【解决方案1】:

模拟器可以正常工作,因为它与计算机位于同一网络上。如果要在手机上使用 URL,则必须连接到服务器的网络。您使用的是本地 IP 地址,因此您应该在同一个网络上。这将使用您手机的无线连接。

您可以做的另一件事是使用您的外部 IP 地址,这样您就不需要在同一个网络上。你应该用谷歌搜索细节,但我认为你只需要找到你的 external IP 地址 (whatismyip.com) 并确保你要连接的端口在路由器的设置中是打开的(通常是端口 80 )。这样您就可以使用手机的 3G 或 4G。

【讨论】:

  • 没问题,是这个问题吗?
【解决方案2】:

我的node.js server也遇到了同样的问题

我是如何解决这个问题的:

  1. 在你的电脑上打开Control Panel
  2. 点击System and Security
  3. Windows Defender Firewall下方点击Allows app through windows firewall
  4. 找到Node.js server-side Javascript并将其标记为正确

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-10
    • 2012-04-16
    • 2014-09-01
    • 2012-09-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多