UdpClient receiver = null;
try
{
receiver
= new UdpClient
(port
); receiver.Client.ReceiveTimeout = 3000;
IPEndPoint sourceAddress
= new IPEndPoint
(IPAddress
.Any,
0);
for (; ; )
{
byte[] data = receiver.Receive(ref sourceAddress);
if (ParseResponse(Encoding.ASCII.GetString(data, 0, data.Length)))
{
receiver.Close();
lock (mThreads)
{
mGatewayAddress = sourceAddress.Address;
mStatus = Status.Success;
mThreads.Remove(th);
}
return;
}
}
}
#if DEBUG
catch (System.Exception ex)
{
#if UNITY_EDITOR
UnityEngine.Debug.LogWarning(ex.Message);
#else
Console.WriteLine("ERROR: (UPnP) " + ex.Message);
#endif
}
#else
catch (System.Exception) { }
#endif
if (receiver != null) receiver.Close();