C# RDP application with STUN

2019-08-31 18:34发布

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

标签: c# rdp stun
2条回答
老娘就宠你
2楼-- · 2019-08-31 19:15

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
}
查看更多
可以哭但决不认输i
3楼-- · 2019-08-31 19:22

You can try use http://en.wikipedia.org/wiki/UDP_hole_punching it's very simple and easy to implement

查看更多
登录 后发表回答