Implemented the server form. Client <-> Server interaction actually works.

Fixed a few bugs in the CustomServer - wasn't configuring the listen socket correctly, doing read/write operations from the wrong socket, etc. Reworked how the CustomConnection class handles serialization.

Added Disconnected events to the sample's CustomConnection and CustomServer classes so the forms could reset state.
This commit is contained in:
antiduh
2014-06-26 18:00:50 +00:00
parent 81ed80a4d0
commit 5b3a92ee66
8 changed files with 626 additions and 17 deletions

View File

@@ -28,12 +28,226 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.label1 = new System.Windows.Forms.Label();
this.portNumeric = new System.Windows.Forms.NumericUpDown();
this.startButton = new System.Windows.Forms.Button();
this.stopButton = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.usernameTextbox = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.sendTextbox = new System.Windows.Forms.TextBox();
this.receivedTextbox = new System.Windows.Forms.TextBox();
this.encryptButton = new System.Windows.Forms.Button();
this.signButton = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.portNumeric)).BeginInit();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 21);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(83, 13);
this.label1.TabIndex = 0;
this.label1.Text = "Port to listen on:";
//
// portNumeric
//
this.portNumeric.Location = new System.Drawing.Point(101, 19);
this.portNumeric.Maximum = new decimal(new int[] {
65536,
0,
0,
0});
this.portNumeric.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.portNumeric.Name = "portNumeric";
this.portNumeric.Size = new System.Drawing.Size(69, 20);
this.portNumeric.TabIndex = 1;
this.portNumeric.Value = new decimal(new int[] {
10000,
0,
0,
0});
//
// startButton
//
this.startButton.Location = new System.Drawing.Point(196, 16);
this.startButton.Name = "startButton";
this.startButton.Size = new System.Drawing.Size(75, 23);
this.startButton.TabIndex = 2;
this.startButton.Text = "Start server";
this.startButton.UseVisualStyleBackColor = true;
//
// stopButton
//
this.stopButton.Location = new System.Drawing.Point(277, 16);
this.stopButton.Name = "stopButton";
this.stopButton.Size = new System.Drawing.Size(75, 23);
this.stopButton.TabIndex = 3;
this.stopButton.Text = "Stop server";
this.stopButton.UseVisualStyleBackColor = true;
//
// groupBox1
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.usernameTextbox);
this.groupBox1.Location = new System.Drawing.Point(400, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(313, 65);
this.groupBox1.TabIndex = 4;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Server credentials";
//
// usernameTextbox
//
this.usernameTextbox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.usernameTextbox.Location = new System.Drawing.Point(74, 20);
this.usernameTextbox.Name = "usernameTextbox";
this.usernameTextbox.ReadOnly = true;
this.usernameTextbox.Size = new System.Drawing.Size(233, 20);
this.usernameTextbox.TabIndex = 0;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(7, 23);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(61, 13);
this.label2.TabIndex = 1;
this.label2.Text = "User name:";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.signButton);
this.groupBox2.Controls.Add(this.encryptButton);
this.groupBox2.Controls.Add(this.sendTextbox);
this.groupBox2.Dock = System.Windows.Forms.DockStyle.Fill;
this.groupBox2.Location = new System.Drawing.Point(3, 3);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(344, 381);
this.groupBox2.TabIndex = 5;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Send a message to the client";
//
// groupBox3
//
this.groupBox3.Controls.Add(this.receivedTextbox);
this.groupBox3.Dock = System.Windows.Forms.DockStyle.Fill;
this.groupBox3.Location = new System.Drawing.Point(353, 3);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(345, 381);
this.groupBox3.TabIndex = 6;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Received messages from the client";
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Controls.Add(this.groupBox2, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.groupBox3, 1, 0);
this.tableLayoutPanel1.Location = new System.Drawing.Point(12, 87);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 1;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(701, 387);
this.tableLayoutPanel1.TabIndex = 7;
//
// sendTextbox
//
this.sendTextbox.Location = new System.Drawing.Point(6, 19);
this.sendTextbox.Multiline = true;
this.sendTextbox.Name = "sendTextbox";
this.sendTextbox.Size = new System.Drawing.Size(331, 322);
this.sendTextbox.TabIndex = 0;
//
// receivedTextbox
//
this.receivedTextbox.Dock = System.Windows.Forms.DockStyle.Fill;
this.receivedTextbox.Location = new System.Drawing.Point(3, 16);
this.receivedTextbox.Multiline = true;
this.receivedTextbox.Name = "receivedTextbox";
this.receivedTextbox.Size = new System.Drawing.Size(339, 362);
this.receivedTextbox.TabIndex = 0;
//
// encryptButton
//
this.encryptButton.Location = new System.Drawing.Point(33, 349);
this.encryptButton.Name = "encryptButton";
this.encryptButton.Size = new System.Drawing.Size(120, 23);
this.encryptButton.TabIndex = 2;
this.encryptButton.Text = "Encrypt and send";
this.encryptButton.UseVisualStyleBackColor = true;
//
// signButton
//
this.signButton.Location = new System.Drawing.Point(174, 349);
this.signButton.Name = "signButton";
this.signButton.Size = new System.Drawing.Size(117, 23);
this.signButton.TabIndex = 3;
this.signButton.Text = "Sign and send";
this.signButton.UseVisualStyleBackColor = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "Form1";
this.ClientSize = new System.Drawing.Size(725, 477);
this.Controls.Add(this.tableLayoutPanel1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.stopButton);
this.Controls.Add(this.startButton);
this.Controls.Add(this.portNumeric);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Server - SSPI Test";
((System.ComponentModel.ISupportInitialize)(this.portNumeric)).EndInit();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
this.tableLayoutPanel1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.NumericUpDown portNumeric;
private System.Windows.Forms.Button startButton;
private System.Windows.Forms.Button stopButton;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox usernameTextbox;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Button signButton;
private System.Windows.Forms.Button encryptButton;
private System.Windows.Forms.TextBox sendTextbox;
private System.Windows.Forms.TextBox receivedTextbox;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
}
}