Fixed errors in unity 2019, UDPClient receives right away

This commit is contained in:
Derek S 2021-04-05 23:50:34 -05:00
parent 137ff64d17
commit 6595d4ead2
2 changed files with 6 additions and 6 deletions

View file

@ -116,6 +116,7 @@ namespace LightReflectiveMirror
{
IPEndPoint newClientEP = new IPEndPoint(IPAddress.Any, 0);
var data = _NATPuncher.EndReceive(result, ref newClientEP);
_NATPuncher.BeginReceive(new AsyncCallback(RecvData), _NATPuncher);
if (!newClientEP.Address.Equals(_relayPuncherIP.Address))
{
@ -146,8 +147,6 @@ namespace LightReflectiveMirror
}
}
}
_NATPuncher.BeginReceive(new AsyncCallback(RecvData), _NATPuncher);
}
void ServerProcessProxyData(IPEndPoint remoteEndpoint, byte[] data)
@ -505,7 +504,7 @@ namespace LightReflectiveMirror
else
{
relayServerList?.Clear();
relayServerList = JsonConvert.DeserializeObject<List<RelayServerInfo>>(result.Decompress());
relayServerList = JsonConvert.DeserializeObject<List<Room>>(result.Decompress());
serverListUpdated?.Invoke();
}
#endif
@ -557,7 +556,7 @@ namespace LightReflectiveMirror
else
{
relayServerList?.Clear();
relayServerList = JsonConvert.DeserializeObject<List<RelayServerInfo>>(result);
relayServerList = JsonConvert.DeserializeObject<List<Room>>(result);
serverListUpdated?.Invoke();
}
#endif

View file

@ -57,11 +57,12 @@ namespace LightReflectiveMirror
void RecvData(IAsyncResult result)
{
_clientInitialRecv = true;
byte[] data = _udpClient.EndReceive(result, ref _recvEndpoint);
_udpClient.BeginReceive(new AsyncCallback(RecvData), _udpClient);
_clientInitialRecv = true;
lastInteractionTime = DateTime.Now;
dataReceived?.Invoke(_remoteEndpoint, data);
_udpClient.BeginReceive(new AsyncCallback(RecvData), _udpClient);
}
}
}