Make TcpClient connection method timeout

This commit is contained in:
2020-06-13 10:49:31 -05:00
parent ccc2df2fc4
commit a5ff4c05d6
4 changed files with 19 additions and 23 deletions
@@ -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)
@@ -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)