public static void RegisterNat(CrossPlatformUDP socket, ushort port, string proxyHost, ushort proxyPort = PORT)
{
#if !NETFX_CORE
IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse(proxyHost), proxyPort);
List<byte> data = new List<byte>(new byte[] { 4, 4, 1 });
data.AddRange(BitConverter.GetBytes(port));
try
{
int tryCount = 10;
while (socket.ReadClient.Available == 0)
{
socket.ReadClient.Send(data.ToArray(), data.Count, endpoint);
Thread.Sleep(500);
if (--tryCount <= 0)
throw new Exception("Unable to contact proxy host");
}
#if UNITY_EDITOR
Debug.Log("The hole punching registration for this server is complete");
#endif
}
#if UNITY_EDITOR
catch (Exception e)
{
Debug.LogException(e);
}
#else
catch { }
#endif
#endif
}
}