1

What I am trying to do is, send data from my PC(local IP) to another PC(private IP) in internet. I wrote a java program to send/receive messages with stun resolver.

Program:

Resolve stun and get public IP and port
Send message with same socket(resolve stun) to another program.
Receiving with same socket(resolve stun) in different thread.

We are sending data to each other's public IP/port resolved by stun. I'm not sure about other end but my network has Port restricted clone NAT. Am I doing any wrong??

Note: NAT is tested. I communicated with a server and a local mobile device with stun resolve.

Edit

I don't have any firewall. I also stopped ufw service.

System:

Ubuntu 14.04
Mac 10.10.3
Community
  • 1
  • 1
shantanu
  • 2,408
  • 2
  • 26
  • 56

2 Answers2

2

Short summary: After discovering your STUN ip/port for your socket, you need to send a 1 byte "hole punching packet" to the remote endpoint's IP and port. This will allow incoming traffic from that address. The other side should do the same thing.

Long answer: My previous write-up on P2P socket programming here.

Community
  • 1
  • 1
selbie
  • 100,020
  • 15
  • 103
  • 173
  • Thank you for quick reply. About the hole punching, as soon as we both know our IP/Port(public) we started to send data to each other. But we never received anything. – shantanu Jul 09 '15 at 18:35
  • P2P socket networking with NAT traversal is very challenging and not an exact science. Ideally, you have traffic monitoring utilities on both sides of the NATs to diagnose these types of problems. – selbie Jul 09 '15 at 23:55
1

You need to punch a hole in both side's NAT for the NATs to allow the incoming packets. You should punch hole with low ttl value. So that the packet you send for hole punching doesn't reach other side NAT. If it does than all the packet after that from your ip to that NAT may be blocked. Not all NATs are configured like this. This could be a reason for you both not receiving anything.

There could be another reason. Your other NAT could be a symmetric NAT. In this case you will need a TURN server to establish connectivity.

Also you do not need to punch hole if other side's NAT is Full Cone. So you really need to know the other side's NAT type to find your problem.

Tahlil
  • 2,680
  • 6
  • 43
  • 84