Skip to content

Commit

Permalink
Add try-catch when processing data received
Browse files Browse the repository at this point in the history
  • Loading branch information
KirisameMarisa committed Feb 18, 2024
1 parent c346505 commit 620aeec
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ private IEnumerator Connect(string inIPAddress, int inPort)
yield break;
}

/// <summary>
/// Disconnects the socket.
/// </summary>
public void DisConnect()

private void OnDestroy()
{
if(IsConnect())
if (IsConnect())
{
socket.Disconnect(true);
}
}

/// <summary>
Expand Down Expand Up @@ -94,14 +94,18 @@ private IEnumerator ProcessReceiveData()
var task = socket.ReceiveAsync(receivedData, SocketFlags.None);
yield return new WaitUntil(() => task.IsCompleted);

int bytesRead = task.Result;
if (task.Result > 0)
try
{
Console.WriteLine("ProcessReceiveData::Success, size=" + bytesRead);
List<byte> receivedDataList = new List<byte>(receivedData);
receivedDataList.RemoveRange(bytesRead, receivedData.Length - bytesRead);
ReciveCallback?.Invoke(receivedDataList);
int bytesRead = task.Result;
if (task.Result > 0)
{
Console.WriteLine("ProcessReceiveData::Success, size=" + bytesRead);
List<byte> receivedDataList = new List<byte>(receivedData);
receivedDataList.RemoveRange(bytesRead, receivedData.Length - bytesRead);
ReciveCallback?.Invoke(receivedDataList);
}
}
catch { }
}

/// <summary>
Expand Down

0 comments on commit 620aeec

Please sign in to comment.