I´m trying to do a p2p file sharing proto/software in Java. I am interested in learning using socket so, no I will not use JXTA or any kind of API.
I read about TCP hole punching, and it may not work on all NAT types. But I can see that Gnutella and BitTorrent always works on every machine/NAT I try. So do they use TCP Hole Punching to initiate a connection between hosts?
Also, a code like this would do the TCP Hole Punching?
final ServerSocket s = new ServerSocket(7777);
Thread t = new Thread(new Runnable(){
public void run() {
try
{
s.accept();
}
catch(Exception ex)
{
}
}
});
Socket sock = new Socket();
sock.connect(new InetSocketAddress("IP ADDRESS", 7777), 50000);