BeardedManStudios.Network.Networking.LanDiscovery C# (CSharp) Метод

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

public static LanDiscovery ( ushort port, int listenWaitTime = 10000, TransportationProtocolType protocol = TransportationProtocolType.UDP, bool winRT = false ) : IPEndPoint
port ushort
listenWaitTime int
protocol TransportationProtocolType
winRT bool
Результат System.Net.IPEndPoint
		public static IPEndPoint LanDiscovery(ushort port, int listenWaitTime = 10000, TransportationProtocolType protocol = TransportationProtocolType.UDP, bool winRT = false)
#endif
		{
#if !NETFX_CORE && !UNITY_WEBPLAYER
			UdpClient Client = new UdpClient();
			IPEndPoint foundEndpoint = new IPEndPoint(IPAddress.Any, 0);
			bool found = false;

			List<string> localSubNet = new List<string>();

			foreach (System.Net.NetworkInformation.NetworkInterface f in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces())
			{
				if (f.OperationalStatus == System.Net.NetworkInformation.OperationalStatus.Up)
				{
					foreach (System.Net.NetworkInformation.GatewayIPAddressInformation d in f.GetIPProperties().GatewayAddresses)
					{
						if (d.Address.ToString() == "0.0.0.0") continue;

						if (d.Address.ToString().Contains("."))
							localSubNet.Add(d.Address.ToString().Remove(d.Address.ToString().LastIndexOf('.')));
					}
				}
			}

			foreach (string s in localSubNet)
				Client.Send(new byte[1], 1, new IPEndPoint(IPAddress.Parse(s + ".255"), port));

			int counter = 0;
			do
			{
				if (Client.Available != 0)
				{
					Client.Receive(ref foundEndpoint);
					found = true;
					break;
				}

				if (counter++ > listenWaitTime / 50)
					break;

				System.Threading.Thread.Sleep(50);
				foreach (string s in localSubNet)
					Client.Send(new byte[1], 1, new IPEndPoint(IPAddress.Parse(s + ".255"), port));
			} while (true);

			Client.Close();

			if (found)
				return foundEndpoint;
#elif NETFX_CORE
			// TODO:  Implement
#elif UNITY_WEBPLAYER
			Debug.LogError("Unable to find local at this time for webplayer");
#endif

			return null;
		}

Same methods

Networking::LanDiscovery ( ushort port, int listenWaitTime = 10000, TransportationProtocolType protocol = TransportationProtocolType.UDP, bool winRT = false ) : IPEndPointWinRT