Sorry if this has been posted somewhere I’ve been working/looking for days.
The Problem:
I’m getting SocketTimeoutExceptions when communicating via a peer to peer network with android devices.
Details:
The android devices use their own mobile network and not wifi when this happens(wifi wasn’t designed to work with this anyways).
The android devices successfully get their ipAddress from whatismyip.com.
One device will send the other their ip address via other means than the peer to peer network we’re using.
The ip address of the remote device will come successfully to the local device.
When the local device responds via the peer to peer network a TimeoutException occurs.
What I’ve tried:
Extending the timeout to significantly long periods of time.
Using other android devices.
Notable:
It should be noted that this same peer to peer network has been tested to successfully work amongst PCs(running linux and windows if that matters) on a local area network. Also just tested the peer to peer network across our wired internet connections on our PCs and it definitely works.
My guess:
I’m thinking that the device is hidden by the isp somehow and I’m going to have to write some code to do something similar to nat traversal but I’m not quite sure. But then again if the device is being hidden I should get a connection refused exception.
Any help is much appreciated.
P.S. I’m unable to post code at the moment and even if I could it’s a couple thousand lines of code for the whole process.
What you should try is to effectively debug your connection,the first thing you could do is check isReachable as hinted in android dev even if unfortunately some networks blocks ICMP.
Another important thing to note is even if you use 3g,your network can still use NAT addresses,and it is very common believe me,so the ip you see on whatsmyip could aswell be a NATed ip.
Next step i would reccomend is to try to use your app in a hybrid mode,that is one pc and one android device and try to connect to the pc(make sure that one has public ip or atleast forwarded ports) if that works you know for sure it is your mobile carrier.
If that really proves to be the case,there is nothing you can do except use wifi,or use a local server to establish connection between two peers.
Also to be noted that p2p networks get stronger the more they grow,you could aswell implement that peers already connected to the network and reachable from the outside help those others to connect to the other peers.You should look up p2p relaying and Hole punching