简体   繁体   English

与PC的Android套接字连接可在模拟器上运行,但不能在设备上运行

[英]Android socket connection with PC works on Emulator but not on Device

I have a little example running that sends a message through a socket from an Android device to the PC. 我有一个运行示例,该示例通过套接字将消息从Android设备发送到PC。 The server is in C++ using an example from this link and the client is a simple Android app. 使用链接中的示例,服务器为C ++,客户端为简单的Android应用。

The problem that I have is that when I run both on my PC (android app on Eclipse's emulator) it works correctly, but when I use an android device I keep getting a java.net.ConnectException due to a connection time out. 我的问题是,当我在PC上(Eclipse的模拟器上的android应用程序)都运行它们时,它可以正常工作,但是当我使用android设备时,由于连接超时,我一直得到java.net.ConnectException。

At first I thought it could be a firewall problem but I created a rule allowing communication through the port that I am using and things kept working in the same way. 起初我以为这可能是防火墙问题,但我创建了一条规则,允许通过我正在使用的端口进行通信,并且一切保持相同的状态。 I tried to switch off the firewall just in case and nothing happened. 我试图关闭防火墙,以防万一。

I have pinged the PC from Android and viceversa and everything is fine. 我从Android ping通PC,反之亦然,一切都很好。

Any ideas on what can I be missing? 关于我可能会缺少的任何想法? Both devices are on the same network of course! 当然,两个设备都在同一网络上!

Thanks in advance. 提前致谢。

First of all, I think it is not a good idea to mix between Java and C++ data through Sockets (I am not sure if ints, floats and that sort are going to be equal in both sides). 首先,我认为通过套接字在Java和C ++数据之间进行混合不是一个好主意(我不确定ints,float和这种类型在两端是否相等)。

Nevertheless, have you given internet permission in the Android XML Manifest? 但是,您是否在Android XML清单中授予了Internet许可?

<uses-permission android:name="android.permission.INTERNET" />

Could you please give us more details about the Server and the Android code? 您能否为我们提供有关服务器和Android代码的更多详细信息?

Thanks! 谢谢!

There appeared to be some kind of firewall blocking incoming requests other than that of Windows. 除了Windows之外,似乎还有某种防火墙阻止传入的请求。 I tried the other way around, starting the communication from Windows' side and everything works like a charm! 我尝试了另一种方法,从Windows端开始进行通信,一切都像个魅力!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM