I'd like to understand better what can be done with networks, and I'm currently working on some Android apps where I'd like to implement some kind of P2P connections, over WiFi and/or 3G/4G, somehow. I know there are many difficulties that arise in doing so, but still, I'd like to know how, or to have a direction on how I could begin to tackle the problem.
I had an idea about it, which I think would avoid me all the hassle of NAT traversing if it works (I definitely not pretend I'm the first guy to come up with this):
Jim and John both connect to the server. The server put them in the same box and relay one another's message. At some point, the server get bored of wasting his bandwidth. He has a connected socket to Jim, and a connected socket to John. So 'somehow' (perhaps magically), he gives his to-John-Socket to Jim, and vice-versa.
Thus the new scenario : Jim comes and say "Hey server, gimme a socket to John": Server: Ok wait here until he arrives. John: Hey server, gimme a socket to Jim. Server: Oh, there you are! Jim, take John's socket. John, take Jim's socket. See ya guys!
Server goes back to his little business while Jim and John do their own things.
I guess it is definitely not this simple. So how should I do this? If I need to traverse NAT gateways at some point, how can I do that (myself, without a library) ?