diff --git a/Plugins/Unity/project/Assets/BocchiTracker/Runtime/BocchiTrackerTcpSocket.cs b/Plugins/Unity/project/Assets/BocchiTracker/Runtime/BocchiTrackerTcpSocket.cs index 15283a0..74a8386 100644 --- a/Plugins/Unity/project/Assets/BocchiTracker/Runtime/BocchiTrackerTcpSocket.cs +++ b/Plugins/Unity/project/Assets/BocchiTracker/Runtime/BocchiTrackerTcpSocket.cs @@ -46,13 +46,12 @@ private IEnumerator Connect(string inIPAddress, int inPort) yield break; } - /// - /// Disconnects the socket. - /// - public void DisConnect() + private void OnDestroy() { - if(IsConnect()) + if (IsConnect()) + { socket.Disconnect(true); + } } /// @@ -94,14 +93,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 receivedDataList = new List(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 receivedDataList = new List(receivedData); + receivedDataList.RemoveRange(bytesRead, receivedData.Length - bytesRead); + ReciveCallback?.Invoke(receivedDataList); + } } + catch { } } ///