LobbyServer/LobbyServerDto/NatPuncher.cs

30 lines
770 B
C#

using System.Net;
using System.Net.Sockets;
namespace LobbyServerDto
{
public class NatPuncher
{
public static void NatPunch(IPEndPoint localEndpoint, IPEndPoint remoteEndpoint)
{
try
{
using Socket socket = new Socket(SocketType.Dgram, ProtocolType.Udp);
socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.ReuseAddress, true);
socket.ExclusiveAddressUse = false;
socket.Bind(localEndpoint);
for (int i = 0; i < 16; i++)
{
socket.SendTo(new byte[] { }, remoteEndpoint);
}
}
catch
{
throw;
}
}
}
}