1
votes

I've been trying to connect two Android devices (2.1) via TCP sockets. The vital part of the code:

Server: ServerSocket serverSocket = new ServerSocket(SERVERPORT);

Client: Socket socket = new Socket(serverAddr, SERVERPORT);

The weird thing is I can make it work if the client is an emulator, but the same code fails if running both of them on real devices. The failure in the client side is:

 
java.net.SocketException: No route to host
     at org.apache.harmony.luni.platform.OSNetworkSystem.connectSocketImpl(Native
 Method)
     at org.apache.harmony.luni.platform.OSNetworkSystem.connect(OSNetworkSystem.
java:114)
     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:
245)
     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:
220)
     at java.net.Socket.startupSocket(Socket.java:780)
     at java.net.Socket.(Socket.java:314)

I tried with WIFI and mobile net too, they were in the same subnet both times, INTERNET permission is given, the server is addressed through its real 192.168.. IP.
I am planning to change the socket implementation with setCustomSocketImplFactory().
The problem is crucial in the process of implementing MSRP protocol to Android.
Can anyone give me some advice?

1
What do you mean by real IP if the programs are running on two mobile phones ?user409393
I've just tried to say that the problem is not that I use 10.0.2.15 IP for the real devicesDiepie

1 Answers

1
votes

Very few mobile phones have publicly routable IP addresses. Most are behind NAT.

You may want to consider using C2DM instead:

http://code.google.com/android/c2dm/