Search code examples
javap2pnat

file transfer using p2p connection in java


i want transfer files using p2p connection. There will be a server or any common place to share both A and B computers information for establishing the connection.

I've created p2p connection using LAN.But my question is - for internet how can I detect the IP addresses of the 2 computers for socket programming ? or any other option so that I can transfer files between two computers which are connected with frequently changing IP address ?

Thanks in advance.


Solution

  • JXTA is a framework that can do that for you. I wrote a book called Practical JXTA which is available for reading online at Scribd. It contains complete code examples. You want to work with release 2.6 or 2.7.

    If you don't want to use a framework, your central peer should be able to read the NAT-translated address of your remote edge peers, when they connect to it (see Socket#getRemoteSocketAddress()) . But that won't help with TCP (to make it simple). If you use UDP, then you stand a chance, because once a UDP hole is punched in a NAT, many peers can (usually) connect to it.