From a5ff4c05d6d3d34cb01b1ce707cff2a1bc292a3f Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Sat, 13 Jun 2020 10:49:31 -0500 Subject: [PATCH] Make TcpClient connection method timeout --- Droid/qController.Droid.csproj | 8 ------ iOS/qController.iOS.csproj | 4 +-- .../Communication/SharpOSC/TCPClient.cs | 25 ++++++++++--------- .../Pages/ControlPage.xaml.cs | 5 +++- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/Droid/qController.Droid.csproj b/Droid/qController.Droid.csproj index f155590..f3e512e 100644 --- a/Droid/qController.Droid.csproj +++ b/Droid/qController.Droid.csproj @@ -29,10 +29,6 @@ x86;armeabi-v7a;arm64-v8a;x86_64 - false - false - false - false true @@ -54,10 +50,6 @@ armeabi-v7a;x86;arm64-v8a;x86_64 - false - false - false - false diff --git a/iOS/qController.iOS.csproj b/iOS/qController.iOS.csproj index 337e912..10828fd 100644 --- a/iOS/qController.iOS.csproj +++ b/iOS/qController.iOS.csproj @@ -52,13 +52,13 @@ bin\iPhoneSimulator\Release prompt 4 - iPhone Developer: Joel Wetzell (5E8CU66YWB) + iPhone Distribution: Joel Wetzell (JHA7H7P56J) true None x86_64 HttpClientHandler x86 - VS: com.jwetzell.qController Development + qController -v -v -v -v diff --git a/qController.Standard/Classes/Communication/SharpOSC/TCPClient.cs b/qController.Standard/Classes/Communication/SharpOSC/TCPClient.cs index cf11ca1..6dce513 100644 --- a/qController.Standard/Classes/Communication/SharpOSC/TCPClient.cs +++ b/qController.Standard/Classes/Communication/SharpOSC/TCPClient.cs @@ -48,19 +48,16 @@ namespace SharpOSC public bool Connect() { - try + client = new TcpClient(); + + if (!client.ConnectAsync(Address, Port).Wait(TimeSpan.FromSeconds(1))) { - client = new TcpClient(Address, Port); - Thread receivingThread = new Thread(ReceiveLoop); - receivingThread.Start(); - //Console.WriteLine($"TCPClient - connected to <{Address}:{Port}>"); - return true; - } - catch (Exception e) - { - Console.WriteLine(e.Message); return false; } + + Thread receivingThread = new Thread(ReceiveLoop); + receivingThread.Start(); + return true; } @@ -161,8 +158,12 @@ namespace SharpOSC public void Close() { - client.GetStream().Close(); - client.Close(); + if (client.Connected) + { + client.GetStream().Close(); + client.Close(); + } + } protected virtual void OnMessageReceived(OscMessage msg) diff --git a/qController.Standard/Pages/ControlPage.xaml.cs b/qController.Standard/Pages/ControlPage.xaml.cs index 6f79b29..75e8ca7 100644 --- a/qController.Standard/Pages/ControlPage.xaml.cs +++ b/qController.Standard/Pages/ControlPage.xaml.cs @@ -45,7 +45,10 @@ namespace qController App.showToast("Error connecting...make sure QLab is running"); Back(); } - qController.KickOff(); + else + { + qController.KickOff(); + } } private void OnWorkspaceSelected(object source, WorkspacePromptArgs args)