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();
}
}
}
+20 -6
View File
@@ -37,6 +37,7 @@
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
this.connectButton = new System.Windows.Forms.Button();
this.disconnectButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// workspaceListView
@@ -47,10 +48,10 @@
this.workspaceListView.FullRowSelect = true;
this.workspaceListView.GridLines = true;
this.workspaceListView.HideSelection = false;
this.workspaceListView.Location = new System.Drawing.Point(208, 122);
this.workspaceListView.Location = new System.Drawing.Point(246, 122);
this.workspaceListView.MultiSelect = false;
this.workspaceListView.Name = "workspaceListView";
this.workspaceListView.Size = new System.Drawing.Size(580, 316);
this.workspaceListView.Size = new System.Drawing.Size(542, 316);
this.workspaceListView.TabIndex = 0;
this.workspaceListView.UseCompatibleStateImageBehavior = false;
this.workspaceListView.View = System.Windows.Forms.View.Details;
@@ -68,7 +69,7 @@
//
// goButton
//
this.goButton.Location = new System.Drawing.Point(208, 47);
this.goButton.Location = new System.Drawing.Point(246, 47);
this.goButton.Name = "goButton";
this.goButton.Size = new System.Drawing.Size(104, 69);
this.goButton.TabIndex = 1;
@@ -96,7 +97,7 @@
this.serverListView.HideSelection = false;
this.serverListView.Location = new System.Drawing.Point(13, 47);
this.serverListView.Name = "serverListView";
this.serverListView.Size = new System.Drawing.Size(189, 391);
this.serverListView.Size = new System.Drawing.Size(227, 391);
this.serverListView.TabIndex = 4;
this.serverListView.UseCompatibleStateImageBehavior = false;
this.serverListView.View = System.Windows.Forms.View.Details;
@@ -113,7 +114,7 @@
//
// connectButton
//
this.connectButton.Location = new System.Drawing.Point(94, 21);
this.connectButton.Location = new System.Drawing.Point(72, 21);
this.connectButton.Name = "connectButton";
this.connectButton.Size = new System.Drawing.Size(75, 23);
this.connectButton.TabIndex = 5;
@@ -121,11 +122,23 @@
this.connectButton.UseVisualStyleBackColor = true;
this.connectButton.Click += new System.EventHandler(this.connectButton_Click);
//
// disconnectButton
//
this.disconnectButton.Enabled = false;
this.disconnectButton.Location = new System.Drawing.Point(153, 21);
this.disconnectButton.Name = "disconnectButton";
this.disconnectButton.Size = new System.Drawing.Size(75, 23);
this.disconnectButton.TabIndex = 5;
this.disconnectButton.Text = "Disconnect";
this.disconnectButton.UseVisualStyleBackColor = true;
this.disconnectButton.Click += new System.EventHandler(this.disconnectButton_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.ClientSize = new System.Drawing.Size(842, 480);
this.Controls.Add(this.disconnectButton);
this.Controls.Add(this.connectButton);
this.Controls.Add(this.serverListView);
this.Controls.Add(this.label1);
@@ -152,6 +165,7 @@
private System.Windows.Forms.Button connectButton;
private System.Windows.Forms.ColumnHeader columnHeader4;
private System.Windows.Forms.ColumnHeader cueNameHeader;
private System.Windows.Forms.Button disconnectButton;
}
}
+27 -9
View File
@@ -46,23 +46,41 @@ namespace QSharpDemoApp
private void connectButton_Click(object sender, EventArgs e)
{
if(serverListView.SelectedItems.Count == 1)
if(connectedWorkspace == null)
{
QServer server = browser.serverForAddress(serverListView.SelectedItems[0].SubItems[3].Text);
string workspaceID = serverListView.SelectedItems[0].SubItems[2].Text;
if (server != null)
if (serverListView.SelectedItems.Count == 1)
{
connectedWorkspace = server.workspaceWithID(workspaceID);
if(connectedWorkspace != null)
QServer server = browser.serverForAddress(serverListView.SelectedItems[0].SubItems[3].Text);
string workspaceID = serverListView.SelectedItems[0].SubItems[2].Text;
if (server != null)
{
connectedWorkspace.WorkspaceUpdated += Workspace_WorkspaceUpdated;
connectedWorkspace.connectWithPasscode("");
connectedWorkspace = server.workspaceWithID(workspaceID);
if (connectedWorkspace != null)
{
connectedWorkspace.WorkspaceUpdated += Workspace_WorkspaceUpdated;
connectedWorkspace.connectWithPasscode("");
connectButton.Enabled = false;
disconnectButton.Enabled = true;
}
}
}
}
}
private void disconnectButton_Click(object sender, EventArgs e)
{
if (connectedWorkspace != null)
{
connectedWorkspace.disconnect();
connectButton.Enabled = true;
disconnectButton.Enabled = false;
connectedWorkspace = null;
workspaceListView.Items.Clear();
}
}
private void Server_ServerUpdated(object source, QServerUpdatedArgs args)
{
QServer server = args.server;