diff --git a/Runtime/Client.cs b/Runtime/Client.cs index 0e6ac4e..12e81f0 100644 --- a/Runtime/Client.cs +++ b/Runtime/Client.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Net.Sockets; using System.Collections.Generic; using System.Collections; @@ -10,6 +10,7 @@ using System.Security.Cryptography.X509Certificates; using System.Security.Authentication; using System.IO; +using UnityEngine.Events; namespace Sand { @@ -36,6 +37,7 @@ public class Client : MonoBehaviour public bool useTLS = false; public bool leaveInnerStreamOpen = false; public bool validateCert = true; + public UnityEvent sandReadingException = new UnityEvent(); private string eventDelimiter = "#e#"; private string packetDelimiter = "\n"; @@ -70,6 +72,25 @@ public void Connect() } } + public void Disconnect() + { + try + { + if (queueReadingRoutine != null) + StopCoroutine(queueReadingRoutine); + + if (clientReceiveThread != null) + clientReceiveThread.Abort(); + + if (socketConnection != null) + socketConnection.Close(); + } + catch (Exception ex) + { + Debug.LogError("Disconnecting Client Failed."); + } + } + private IEnumerator ReadingQueuedMessages() { while (true) @@ -112,9 +133,10 @@ private void Reading() } } } - catch (SocketException socketException) - { - Debug.LogError("Socket exception: " + socketException); + catch(Exception e) + { + Debug.LogError("Sand Reading Exception"); + sandReadingException.Invoke(); } } diff --git a/Runtime/com.ccadori.sandsocketunity.Runtime.asmdef b/Runtime/com.ccadori.sandsocketunity.Runtime.asmdef index fe24108..bc2fa93 100644 --- a/Runtime/com.ccadori.sandsocketunity.Runtime.asmdef +++ b/Runtime/com.ccadori.sandsocketunity.Runtime.asmdef @@ -8,7 +8,8 @@ "WSA", "WindowsStandalone32", "WindowsStandalone64", - "XboxOne" + "XboxOne", + "LinuxStandalone64" ], "excludePlatforms": [], "allowUnsafeCode": false, @@ -18,4 +19,4 @@ "defineConstraints": [], "versionDefines": [], "noEngineReferences": false -} \ No newline at end of file +} diff --git a/package.json b/package.json index f992d37..c5e8397 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.ccadori.sandsocketunity", - "version": "1.0.1", + "version": "1.0.3", "displayName": "Sand Socket Unity", "unity": "2019.3", "keywords": [