BeardedManStudios.Network.ForgeMasterServer.RegisterNat C# (CSharp) Метод

RegisterNat() публичный статический Метод

This method is used to allow a server to register itself with the NAT hole punching server
public static RegisterNat ( CrossPlatformUDP socket, ushort port, string proxyHost, ushort proxyPort = PORT ) : void
socket CrossPlatformUDP This is the socket that is being used for the communication with the clients
port ushort The port number that is being used for this server
proxyHost string The ip address of the the NAT hole punching (router) server
proxyPort ushort The port number for the NAT hole punch server
Результат void
		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
		}
	}