Rework workspace/client/tcpclient disconnection

This commit is contained in:
Joel Wetzell
2020-06-16 08:13:22 -05:00
parent 64e1cc787f
commit 549d1d7d08
7 changed files with 71 additions and 44 deletions
+1 -1
View File
@@ -99,7 +99,7 @@ namespace QSharp
{
foreach(var server in servers)
{
server.Close();
server.disconnect();
}
zeroconfTCPBrowser.Dispose();
}
+1 -9
View File
@@ -241,14 +241,6 @@ namespace QSharp
}
WorkspacesUpdated(this, new QWorkspacesUpdatedArgs { Workspaces = workspaces });
}
}
public void Close()
{
this.tcpClient.Close();
}
}
}
}
+7 -4
View File
@@ -71,14 +71,17 @@ namespace QSharp
}
#endregion
public void Close()
public void disconnect()
{
foreach (var workspace in workspaces)
{
if(workspace.connected)
workspace.Close();
if (workspace.connected)
{
Log.Debug($"[server] Close Called For workspace: {workspace.name}");
workspace.disconnect();
}
}
client.Close();
client.disconnect();
}
}
+4 -8
View File
@@ -180,15 +180,16 @@ namespace QSharp
public void disconnect()
{
//TODO
Log.Information($"[workspace] disconnect: {name}");
stopHeartbeat();
if (heartbeatTimer != null)
stopHeartbeat();
stopReceivingUpdates();
disconnectFromWorkspace();
connected = false;
client.disconnect();
//TODO
//root.removeAllChildCues();
}
@@ -531,11 +532,6 @@ namespace QSharp
#endregion
public void Close()
{
client.Close();
}
#region Printing
public void Print()
{
+11 -7
View File
@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Threading;
using Serilog;
namespace SharpOSC
{
@@ -30,7 +31,7 @@ namespace SharpOSC
}
public delegate void MessageReceivedHandler(object source, MessageEventArgs args);
public event MessageReceivedHandler MessageReceived;
private Thread receivingThread;
string _address;
TcpClient client;
@@ -51,9 +52,9 @@ namespace SharpOSC
try
{
client = new TcpClient(Address, Port);
Thread receivingThread = new Thread(ReceiveLoop);
receivingThread = new Thread(ReceiveLoop);
receivingThread.Start();
//Console.WriteLine($"TCPClient - connected to <{Address}:{Port}>");
Console.WriteLine($"[tcpclient] connected to <{Address}:{Port}>");
return true;
}
catch (Exception e)
@@ -94,7 +95,7 @@ namespace SharpOSC
{
Receive();
}
Console.WriteLine("TCPClient - Receive Loop has exited for some reason");
//Log.Debug("[tcpclient] - ReceiveLoop has exited");
}
public void Receive()
@@ -164,10 +165,13 @@ namespace SharpOSC
public void Close()
{
if(client != null || !client.Connected)
if (client != null)
{
client.GetStream().Close();
client.Close();
if (client.Connected)
{
client.GetStream().Close();
client.Close();
}
}
}