Made NATPunch socket keep trying if bind failed (Thanks FakeByte!)
This commit is contained in:
parent
6595d4ead2
commit
689800c377
1 changed files with 15 additions and 4 deletions
|
|
@ -433,10 +433,21 @@ namespace LightReflectiveMirror
|
|||
initalData.WriteString(ref sendPos, data.ReadString(ref pos));
|
||||
NATPunchtroughPort = data.ReadInt(ref pos);
|
||||
|
||||
_NATPuncher = new UdpClient { ExclusiveAddressUse = false };
|
||||
_NATIP = new IPEndPoint(IPAddress.Parse(GetLocalIp()), UnityEngine.Random.Range(16000, 17000));
|
||||
_NATPuncher.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
||||
_NATPuncher.Client.Bind(_NATIP);
|
||||
if (_NATPuncher == null)
|
||||
{
|
||||
_NATPuncher = new UdpClient { ExclusiveAddressUse = false };
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
_NATIP = new IPEndPoint(IPAddress.Parse(GetLocalIp()), UnityEngine.Random.Range(16000, 17000));
|
||||
_NATPuncher.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
||||
_NATPuncher.Client.Bind(_NATIP);
|
||||
break;
|
||||
}
|
||||
catch {} // Binding port is in use, keep trying :P
|
||||
}
|
||||
}
|
||||
|
||||
IPAddress serverAddr;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue