-2

How can i Make android peer to peer Direct File Transfer without using the intermediate server

I Have tried the app with intermediate server but it is not working please help me.

Krunal
  • 61
  • 1
  • 1
  • 6

1 Answers1

0

THis one is actually quite trickey... nearly impossible in many cases.

Basically: To Allow a direct P2P connecion between two devices, one device has to initiate the connection to the other device, which can just answer.

So one device has to open up a connection to an IP-Adress and a Port where the other device is reachable. If you are connected to the same WLAN Accesspoint, you can just display your local IP-Adress on one device and open up a direct connection between the two on any port you want.

If the devices are in different Wireless Networks or one is connected via 3G you have a bunch of problems, starting with NAT. You would have to find a way for one device to read his public IP-Adress (possibly via a STUN-Server) and pass this information to the other client. Then your accesspoint would have to Support UPnP or some similar NAT-Traversal so the other client can reach you, if its not blocked by the ISP, Router or Phone...

Falco
  • 3,287
  • 23
  • 26
  • will you help me in my source code,i have implemented the app but it is not able to find the peers – Krunal Apr 17 '14 at 08:42
  • How are you searching the peers? Are they in the same Wifi? Are you trying broadcasting for discovery? This may be blocked in many Wifis - The best way would to set one Device to "Listen" it opens up a port and waits for incoming connection and displays the IP-Adress to the User. The second device will then connect and the user will enter the target IP-Adress – Falco Apr 17 '14 at 09:38
  • I am Searching for the peers in the same wifi,but still not able to connect the other device – Krunal Apr 17 '14 at 09:45
  • How are you searching? Do you open a direct connection to an explicit IP-Adress and port? – Falco Apr 17 '14 at 09:51
  • yes open the direct connection using the port. – Krunal Apr 17 '14 at 09:54
  • port = ((Integer) intent.getExtras().get("port")).intValue(); – Krunal Apr 17 '14 at 09:55
  • Try a Telnet session from your PC in the same network to the device on the same port - this will also help you in later debugging... Try if you can Ping the device from your PC. You have to be careful -many Public Wifis are Outbound only, so all connected Devices can not reach each other and can only connect to the internet! – Falco Apr 17 '14 at 14:12