简体   繁体   中英

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. The server is in C++ using an example from this link and the client is a simple Android app.

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.

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.

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).

Nevertheless, have you given internet permission in the Android XML Manifest?

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

Could you please give us more details about the Server and the Android code?

Thanks!

There appeared to be some kind of firewall blocking incoming requests other than that of Windows. I tried the other way around, starting the communication from Windows' side and everything works like a charm!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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