Take the 2-minute tour ×

I want to make P2P connection between 2 clients behind NAT. I studied methods to make it work and I want to try "UDP hole punching method".


I made a server in PHP, which can send connection details to clients on demand (Like remote IP, remote port).

Source code as example is here: http://pastebin.com/FdiKMSFq

Next, I made an Client in C# which permanently connects to server and ask him about another client info. Client recieves remote IP and remote port (used for connection with server) of another client and tries to connect.

Full source code here: http://pastebin.com/VUJyZivW

First step (connecting, and asking for details) are OK, but when client (A) connects to another client (B) and send some data (A->B), client B do not recieve any data.

I set both IPEndPoints working with port 2000. But it didn't work anyway.


  • A:, server gets
  • B:, server gets
  • A tries to connect on and send some data
share|improve this question

1 Answer 1

Looking over your example, B's NAT is going to drop the packet destined for its public endpoint (pair of address and port). This is because B's NAT sees this as an unsolicited request.

In order for B's NAT to let the packet from A through, it has to think that B had communicated with A prior, thus considering the request solicited. The NAT keeps an internal table to track this.

The way you can establish the connection is by having B send a packet to A's public endpoint ( as well. Doing this will "punch" a hole in B's NAT. In your example A is already "punching" a hole by sending traffic to B.

Keep in mind that this will only work if at least one of the NATs consistently translates private source endpoints to public source endpoints (regardless of destination address). This is because otherwise the public endpoint seen by your server may be different than the one seen by the P2P peers' NAT even when the peers are using the same private endpoint.

share|improve this answer

Your Answer


