I have searched all most all the links in the internet about NAT traversing with C# and STUN. I got the public IP and the port that is using by the application. On most webpages i've read about STUN, a protocol, which should help me to connect to another client behind a NAT-Router or a firewall. Now my question... if I understand STUN, STUN is ONLY there to give me the public IP-Address and the characterization of my NAT.
But so HOW can I connect with this informations to another client?
here is the example I used to configure the STUN with my application
http://www.codeproject.com/Articles/18492/STUN-Client
Here is a c# implementation:
http://www.codeproject.com/Articles/18492/STUN-Client
Example usage:
// Create new socket for STUN client.
Socket socket = new Socket
(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp);
socket.Bind(new IPEndPoint(IPAddress.Any,0));
// Query STUN server
STUN_Result result = STUN_Client.Query("stunserver.org",3478,socket);
if(result.NetType != STUN_NetType.UdpBlocked){
// UDP blocked or !!!! bad STUN server
}
else{
IPEndPoint publicEP = result.PublicEndPoint;
// Do your stuff
}
You can try use http://en.wikipedia.org/wiki/UDP_hole_punching it's very simple and easy to implement