# HG changeset patch # User sl # Date 1408034243 -7200 # Node ID c4e03315035c28993976d15c0cdac7cab52ed20a # Parent 2aa3974c485f3c5ac974f963fc971538cc120417 Client/Server duplex is still a mess in C#. diff -r 2aa3974c485f -r c4e03315035c Client/Client.cs --- a/Client/Client.cs Thu Aug 14 10:41:44 2014 +0200 +++ b/Client/Client.cs Thu Aug 14 18:37:23 2014 +0200 @@ -32,6 +32,7 @@ //MessageBox.Show("OnServerClosing()", "Client"); Program.iMainForm.CloseConnection(); + Program.iMainForm.Close(); } //From IDisposable diff -r 2aa3974c485f -r c4e03315035c Client/MainForm.Designer.cs --- a/Client/MainForm.Designer.cs Thu Aug 14 10:41:44 2014 +0200 +++ b/Client/MainForm.Designer.cs Thu Aug 14 18:37:23 2014 +0200 @@ -48,7 +48,7 @@ this.ClientSize = new System.Drawing.Size(443, 252); this.Controls.Add(this.buttonSetText); this.Name = "MainForm"; - this.Text = "Sharp Display Client"; + this.Text = "Client"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing); this.Load += new System.EventHandler(this.MainForm_Load); this.ResumeLayout(false); diff -r 2aa3974c485f -r c4e03315035c Client/MainForm.cs --- a/Client/MainForm.cs Thu Aug 14 10:41:44 2014 +0200 +++ b/Client/MainForm.cs Thu Aug 14 18:37:23 2014 +0200 @@ -37,24 +37,38 @@ InstanceContext instanceContext = new InstanceContext(iCallback); iClient = new Client(instanceContext); - iClient.Connect("TestClient"); + //Connect using unique name + string name = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"); + iClient.Connect(name); + Text = Text + ": " + name; } public void CloseConnection() { - iClient.Close(); + if (IsClientReady()) + { + //iClient.Disconnect(); + iClient.Close(); + } + iClient = null; iCallback = null; } private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { - if (iClient != null) //Could catch exception instead + if (IsClientReady()) //Could catch exception instead { iClient.Disconnect(); - CloseConnection(); } + + CloseConnection(); + } + + public bool IsClientReady() + { + return (iClient != null && iClient.State == CommunicationState.Opened); } } } diff -r 2aa3974c485f -r c4e03315035c Server/MainForm.Designer.cs --- a/Server/MainForm.Designer.cs Thu Aug 14 10:41:44 2014 +0200 +++ b/Server/MainForm.Designer.cs Thu Aug 14 18:37:23 2014 +0200 @@ -31,6 +31,7 @@ this.components = new System.ComponentModel.Container(); this.tabControl = new System.Windows.Forms.TabControl(); this.tabPageDisplay = new System.Windows.Forms.TabPage(); + this.checkBoxFixedPitchFontOnly = new System.Windows.Forms.CheckBox(); this.buttonSuspend = new System.Windows.Forms.Button(); this.buttonStartClient = new System.Windows.Forms.Button(); this.checkBoxReverseScreen = new System.Windows.Forms.CheckBox(); @@ -55,7 +56,7 @@ this.toolStripStatusLabelSpring = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelPower = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelFps = new System.Windows.Forms.ToolStripStatusLabel(); - this.checkBoxFixedPitchFontOnly = new System.Windows.Forms.CheckBox(); + this.buttonCloseClients = new System.Windows.Forms.Button(); this.tabControl.SuspendLayout(); this.tabPageDisplay.SuspendLayout(); this.panelDisplay.SuspendLayout(); @@ -79,6 +80,7 @@ // // tabPageDisplay // + this.tabPageDisplay.Controls.Add(this.buttonCloseClients); this.tabPageDisplay.Controls.Add(this.checkBoxFixedPitchFontOnly); this.tabPageDisplay.Controls.Add(this.buttonSuspend); this.tabPageDisplay.Controls.Add(this.buttonStartClient); @@ -101,6 +103,16 @@ this.tabPageDisplay.Text = "Display"; this.tabPageDisplay.UseVisualStyleBackColor = true; // + // checkBoxFixedPitchFontOnly + // + this.checkBoxFixedPitchFontOnly.AutoSize = true; + this.checkBoxFixedPitchFontOnly.Location = new System.Drawing.Point(113, 275); + this.checkBoxFixedPitchFontOnly.Name = "checkBoxFixedPitchFontOnly"; + this.checkBoxFixedPitchFontOnly.Size = new System.Drawing.Size(120, 17); + this.checkBoxFixedPitchFontOnly.TabIndex = 17; + this.checkBoxFixedPitchFontOnly.Text = "Fixed pitch font only"; + this.checkBoxFixedPitchFontOnly.UseVisualStyleBackColor = true; + // // buttonSuspend // this.buttonSuspend.Location = new System.Drawing.Point(7, 253); @@ -401,15 +413,15 @@ this.toolStripStatusLabelFps.Size = new System.Drawing.Size(26, 17); this.toolStripStatusLabelFps.Text = "FPS"; // - // checkBoxFixedPitchFontOnly + // buttonCloseClients // - this.checkBoxFixedPitchFontOnly.AutoSize = true; - this.checkBoxFixedPitchFontOnly.Location = new System.Drawing.Point(113, 275); - this.checkBoxFixedPitchFontOnly.Name = "checkBoxFixedPitchFontOnly"; - this.checkBoxFixedPitchFontOnly.Size = new System.Drawing.Size(120, 17); - this.checkBoxFixedPitchFontOnly.TabIndex = 17; - this.checkBoxFixedPitchFontOnly.Text = "Fixed pitch font only"; - this.checkBoxFixedPitchFontOnly.UseVisualStyleBackColor = true; + this.buttonCloseClients.Location = new System.Drawing.Point(7, 224); + this.buttonCloseClients.Name = "buttonCloseClients"; + this.buttonCloseClients.Size = new System.Drawing.Size(75, 23); + this.buttonCloseClients.TabIndex = 18; + this.buttonCloseClients.Text = "Close Clients"; + this.buttonCloseClients.UseVisualStyleBackColor = true; + this.buttonCloseClients.Click += new System.EventHandler(this.buttonCloseClients_Click); // // MainForm // @@ -466,6 +478,7 @@ private System.Windows.Forms.Button buttonStartClient; private System.Windows.Forms.Button buttonSuspend; private System.Windows.Forms.CheckBox checkBoxFixedPitchFontOnly; + private System.Windows.Forms.Button buttonCloseClients; } } diff -r 2aa3974c485f -r c4e03315035c Server/MainForm.cs --- a/Server/MainForm.cs Thu Aug 14 10:41:44 2014 +0200 +++ b/Server/MainForm.cs Thu Aug 14 18:37:23 2014 +0200 @@ -30,6 +30,7 @@ /// Our collection of clients /// public Dictionary iClients; + public bool iClosing; public MainForm() { @@ -372,8 +373,15 @@ public void StopServer() { //Tell connected client first? Is that possible? - BroadcastCloseEvent(); - iServiceHost.Close(); + + if (iClients.Count>0) + { + //Tell our clients + BroadcastCloseEvent(); + } + + //iServiceHost.Close(); + } public void BroadcastCloseEvent() @@ -422,6 +430,11 @@ } } + private void buttonCloseClients_Click(object sender, EventArgs e) + { + BroadcastCloseEvent(); + } + } diff -r 2aa3974c485f -r c4e03315035c Server/Servers.cs --- a/Server/Servers.cs Thu Aug 14 10:41:44 2014 +0200 +++ b/Server/Servers.cs Thu Aug 14 18:37:23 2014 +0200 @@ -67,6 +67,7 @@ { Program.iMainForm.iClients.Remove(aClientName); } + }