C# RDP application with STUN

﹥>﹥吖頭↗ 提交于 2020-01-06 11:26:10

问题


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


回答1:


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
}



回答2:


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



来源:https://stackoverflow.com/questions/23339688/c-sharp-rdp-application-with-stun

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!