-1

I am trying to build an application that does p2p file transfer between hosts using Java. It works fine for hosts that have public IPs, but failed when I test it on my home computer.

Then I find that all computers in my house have same IP. So, I conclude that my ISP uses NAT overloading. If my ISP does that, chances are lots of other ISPs do NAT too. I want my application also works even behind NAT.

I did some research and found that UDP may be more suitable in this case because UDP hole punching works much better than TCP hole punching. Is it true? To be honest, I prefer to use TCP, but if UDP works better then I have to use UDP. (I know UDP is not reliable. I need to build some rdt protocol on top of UDP.) Or are there any other good algorithms that I missed?

Alex
  • 2,915
  • 5
  • 28
  • 38

3 Answers3

1

You can simple use UDT for this purpose. It is an open source, high-performance and well-tested protocol written on top of UDP. Basically its Reliable UDP with support for P2P connections and specially optimised for high-performance data transfer.

The Actual UDT project is hosted at following location, http://udt.sourceforge.net/

The Java version of UDT can be found here, http://sourceforge.net/projects/udt-java/

Tayyab
  • 9,951
  • 1
  • 16
  • 19
0

I would suggest using a server between the two peers, even if the server isn't yours - Google Drive or Dropbox maybe?

AMADANON Inc.
  • 5,753
  • 21
  • 31
  • I want the peers to transfer file directly instead of using a server sitting between them. – Alex Jul 07 '13 at 04:43
0

Have you tried using any of the STUN methods?

zaz
  • 445
  • 1
  • 6
  • 12
  • not yet, I got the basic idea from wiki, but it seems very complicated... Is there any open source Java project implementing STUN/TURN? – Alex Jul 07 '13 at 05:08
  • Well, a p2p service between hosts behind NATs isn't going to be simple. The p2p hosts would also be required to act as an intermediary server for other hosts behind NATs, managing the NAT details used to connect. What I would recommend is forwarding the port your service operates on. That way you can use TCP, and people behind NAT can use your service if they forward the port. – zaz Jul 07 '13 at 05:42