Comments and Discussions

I noticed a little fault in STUN_Client.cs. In method DoTransaction a wait time of 100 is specified for the Poll method. However the wait time of the socket.Poll method is in microseconds, not in milliseconds. Therefore a retransmission is done every 100 microseconds rather than every 100 milliseconds as the comment suggests.

I also read that for the new STUN protocol the retransmission timeout should start at a value of 500 milliseconds, so I assume that 100 milliseconds is quite short actually.

Thanks for writing a very good article on Stun client.
I get the public ip and port using your code, but i don't understand yet how to connect with other machine.
can i use the returned socket from stun to coonect with other machine or i have to do something else ?

STUN only helps you to determine your own public IP and UDP port. To connect clients directly via UDP you need 'UDP hole punching'. The best article I found on this is here: http://www.brynosaurus.com/pub/net/p2pnat/

No matter what, you'll additionally need a rendezvous server, which assists in establishing a direct connection between to UPD clients. However, the public STUN servers are still very helpful. In my case I have a hosted website, where I can deploy HTTP web services. However, I cannot connect to the web server via UDP. So the solution is that clients use a public STUN server to determine their public IP and UDP port, then use an HTTP-based web service to transmit rendezvous information (public IP and port), and finally connect to each other directly via UDP again using the UDP hole punching technique.

My problems is that when i've got a global & local mapped address and the next step is to open a communication channel, but i don't know how to do it! Could you please give me a simple example of message transfer between node through STUN?

Check out my answer under 'How i connect to remote machine using Stun'. You'll have to figure out how to use UDP under WCF and use the hole punching technique to make it work. STUN only helps you to find out the necessary info, public IP and port, to do hole punching. You'll also need an additional rendezvous server.