diff --git a/Pepperdash Core/CLZ Builds/PepperDash_Core.clz b/Pepperdash Core/CLZ Builds/PepperDash_Core.clz index e3db02e..88e21c5 100644 Binary files a/Pepperdash Core/CLZ Builds/PepperDash_Core.clz and b/Pepperdash Core/CLZ Builds/PepperDash_Core.clz differ diff --git a/Pepperdash Core/CLZ Builds/PepperDash_Core.dll b/Pepperdash Core/CLZ Builds/PepperDash_Core.dll index 361097b..7fe0247 100644 Binary files a/Pepperdash Core/CLZ Builds/PepperDash_Core.dll and b/Pepperdash Core/CLZ Builds/PepperDash_Core.dll differ diff --git a/Pepperdash Core/Pepperdash Core.suo b/Pepperdash Core/Pepperdash Core.suo index a7a375e..d9b50e2 100644 Binary files a/Pepperdash Core/Pepperdash Core.suo and b/Pepperdash Core/Pepperdash Core.suo differ diff --git a/Pepperdash Core/Pepperdash Core/Comm/GenericHttpSseClient.cs b/Pepperdash Core/Pepperdash Core/Comm/GenericHttpSseClient.cs index 9e5121f..bd0091f 100644 --- a/Pepperdash Core/Pepperdash Core/Comm/GenericHttpSseClient.cs +++ b/Pepperdash Core/Pepperdash Core/Comm/GenericHttpSseClient.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using Crestron.SimplSharp; using Crestron.SimplSharp.CrestronIO; +using Crestron.SimplSharp.Net; using Crestron.SimplSharp.Net.Http; namespace PepperDash.Core @@ -35,6 +36,8 @@ namespace PepperDash.Core HttpClient Client; HttpClientRequest Request; + Connection SseConnection; + public GenericHttpSseClient(string key, string name) { @@ -75,23 +78,38 @@ namespace PepperDash.Core // In order to get a handle on the response stream, we have to get // the request stream first. Boo Client.BeginGetRequestStream(GetRequestStreamCallback, Request, null); - CrestronConsole.PrintLine("Request made!"); + //CrestronConsole.PrintLine("Request made!"); } catch (Exception e) { - ErrorLog.Notice("Exception occured in AsyncWebPostHttps(): " + e.ToString()); + ErrorLog.Notice("Exception occured in InitiateConnection(): " + e); } }); } public void CloseConnection(string s) { - if (Client != null) + try { - Client.Abort(); - IsConnected = false; + if (Client != null) + { + if (SseConnection != null) + { + // Gracefully dispose of any in use resources?? - Debug.Console(1, this, "Client Disconnected"); + SseConnection.Disconnect(); + SseConnection.Close(true); + + Client.Abort(); + } + IsConnected = false; + + Debug.Console(1, this, "Client Disconnected"); + } + } + catch (Exception e) + { + Debug.Console(1, this, "Error Closing SSE Connection: {0}", e); } } @@ -130,14 +148,10 @@ namespace PepperDash.Core // This closes up the GetResponseStream async var response = request.ThisClient.EndGetResponseStream(request); - response.DataConnection.OnBytesReceived += new EventHandler(DataConnection_OnBytesReceived); - - IsConnected = true; + SseConnection = response.DataConnection; Debug.Console(1, this, "Client Disconnected"); -#warning Need to explore using a heartbeat to verify connection to the server - Stream streamResponse = response.ContentStream; // Object containing various states to be passed back to async callback below RequestState asyncState = new RequestState(); @@ -163,11 +177,6 @@ namespace PepperDash.Core } } - void DataConnection_OnBytesReceived(object sender, EventArgs e) - { - Debug.Console(1, this, "DataConnection OnBytesReceived Fired"); - } - /// /// /// @@ -205,13 +214,20 @@ namespace PepperDash.Core return; } - Crestron.SimplSharp.CrestronIO.IAsyncResult asynchronousResult; - do + try { - asynchronousResult = responseStream.BeginRead(requestState.BufferRead, 0, RequestState.BUFFER_SIZE, - new Crestron.SimplSharp.CrestronIO.AsyncCallback(ReadCallBack), requestState); + Crestron.SimplSharp.CrestronIO.IAsyncResult asynchronousResult; + do + { + asynchronousResult = responseStream.BeginRead(requestState.BufferRead, 0, RequestState.BUFFER_SIZE, + new Crestron.SimplSharp.CrestronIO.AsyncCallback(ReadCallBack), requestState); + } + while (asynchronousResult.CompletedSynchronously && !requestState.Done); + } + catch (Exception e) + { + Debug.Console(1, this, "Exception: {0}", e); } - while (asynchronousResult.CompletedSynchronously && !requestState.Done); } else { diff --git a/Pepperdash Core/Pepperdash Core/PepperDash_Core.projectinfo b/Pepperdash Core/Pepperdash Core/PepperDash_Core.projectinfo index 9305589..cbf9eae 100644 Binary files a/Pepperdash Core/Pepperdash Core/PepperDash_Core.projectinfo and b/Pepperdash Core/Pepperdash Core/PepperDash_Core.projectinfo differ