diff --git a/SocketStudy/ClientForm/MainForm.Designer.cs b/SocketStudy/ClientForm/MainForm.Designer.cs
index abf2651..bdcd178 100644
--- a/SocketStudy/ClientForm/MainForm.Designer.cs
+++ b/SocketStudy/ClientForm/MainForm.Designer.cs
@@ -34,23 +34,32 @@ namespace ClientForm
this.objectButton = new System.Windows.Forms.Button();
this.imageButton = new System.Windows.Forms.Button();
this.fileButton = new System.Windows.Forms.Button();
+ this.mainTablePanel = new System.Windows.Forms.TableLayoutPanel();
+ this.panel1 = new System.Windows.Forms.Panel();
+ this.statusStrip = new System.Windows.Forms.StatusStrip();
+ this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
+ this.heartBeatStatus = new System.Windows.Forms.ToolStripStatusLabel();
+ this.mainTablePanel.SuspendLayout();
+ this.panel1.SuspendLayout();
+ this.statusStrip.SuspendLayout();
this.SuspendLayout();
//
// logConsole
//
this.logConsole.BackColor = System.Drawing.Color.Black;
+ this.logConsole.Dock = System.Windows.Forms.DockStyle.Fill;
this.logConsole.ForeColor = System.Drawing.Color.SpringGreen;
- this.logConsole.Location = new System.Drawing.Point(12, 93);
+ this.logConsole.Location = new System.Drawing.Point(153, 4);
this.logConsole.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.logConsole.Multiline = true;
this.logConsole.Name = "logConsole";
this.logConsole.ScrollBars = System.Windows.Forms.ScrollBars.Both;
- this.logConsole.Size = new System.Drawing.Size(470, 344);
+ this.logConsole.Size = new System.Drawing.Size(572, 354);
this.logConsole.TabIndex = 1;
//
// stringButton
//
- this.stringButton.Location = new System.Drawing.Point(34, 39);
+ this.stringButton.Location = new System.Drawing.Point(32, 22);
this.stringButton.Name = "stringButton";
this.stringButton.Size = new System.Drawing.Size(75, 23);
this.stringButton.TabIndex = 2;
@@ -60,7 +69,7 @@ namespace ClientForm
//
// objectButton
//
- this.objectButton.Location = new System.Drawing.Point(146, 39);
+ this.objectButton.Location = new System.Drawing.Point(32, 69);
this.objectButton.Name = "objectButton";
this.objectButton.Size = new System.Drawing.Size(75, 23);
this.objectButton.TabIndex = 2;
@@ -70,7 +79,7 @@ namespace ClientForm
//
// imageButton
//
- this.imageButton.Location = new System.Drawing.Point(268, 39);
+ this.imageButton.Location = new System.Drawing.Point(32, 111);
this.imageButton.Name = "imageButton";
this.imageButton.Size = new System.Drawing.Size(75, 23);
this.imageButton.TabIndex = 2;
@@ -80,7 +89,7 @@ namespace ClientForm
//
// fileButton
//
- this.fileButton.Location = new System.Drawing.Point(379, 39);
+ this.fileButton.Location = new System.Drawing.Point(32, 152);
this.fileButton.Name = "fileButton";
this.fileButton.Size = new System.Drawing.Size(75, 23);
this.fileButton.TabIndex = 2;
@@ -88,19 +97,70 @@ namespace ClientForm
this.fileButton.UseVisualStyleBackColor = true;
this.fileButton.Click += new System.EventHandler(this.fileButton_Click);
//
+ // mainTablePanel
+ //
+ this.mainTablePanel.ColumnCount = 2;
+ this.mainTablePanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 150F));
+ this.mainTablePanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
+ this.mainTablePanel.Controls.Add(this.logConsole, 1, 0);
+ this.mainTablePanel.Controls.Add(this.panel1, 0, 0);
+ this.mainTablePanel.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.mainTablePanel.Location = new System.Drawing.Point(0, 0);
+ this.mainTablePanel.Name = "mainTablePanel";
+ this.mainTablePanel.RowCount = 1;
+ this.mainTablePanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
+ this.mainTablePanel.Size = new System.Drawing.Size(728, 362);
+ this.mainTablePanel.TabIndex = 3;
+ //
+ // panel1
+ //
+ this.panel1.Controls.Add(this.stringButton);
+ this.panel1.Controls.Add(this.fileButton);
+ this.panel1.Controls.Add(this.objectButton);
+ this.panel1.Controls.Add(this.imageButton);
+ this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.panel1.Location = new System.Drawing.Point(3, 3);
+ this.panel1.Name = "panel1";
+ this.panel1.Size = new System.Drawing.Size(144, 356);
+ this.panel1.TabIndex = 2;
+ //
+ // statusStrip
+ //
+ this.statusStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
+ this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.toolStripStatusLabel1,
+ this.heartBeatStatus});
+ this.statusStrip.Location = new System.Drawing.Point(0, 344);
+ this.statusStrip.Name = "statusStrip";
+ this.statusStrip.Size = new System.Drawing.Size(728, 18);
+ this.statusStrip.TabIndex = 4;
+ this.statusStrip.Text = "statusStrip1";
+ //
+ // toolStripStatusLabel1
+ //
+ this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
+ this.toolStripStatusLabel1.Size = new System.Drawing.Size(0, 13);
+ //
+ // heartBeatStatus
+ //
+ this.heartBeatStatus.Name = "heartBeatStatus";
+ this.heartBeatStatus.Size = new System.Drawing.Size(0, 13);
+ //
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(498, 450);
- this.Controls.Add(this.fileButton);
- this.Controls.Add(this.imageButton);
- this.Controls.Add(this.objectButton);
- this.Controls.Add(this.stringButton);
- this.Controls.Add(this.logConsole);
+ this.ClientSize = new System.Drawing.Size(910, 452);
+ this.Controls.Add(this.statusStrip);
+ this.Controls.Add(this.mainTablePanel);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "MainForm";
this.Text = "Client";
+ this.mainTablePanel.ResumeLayout(false);
+ this.mainTablePanel.PerformLayout();
+ this.panel1.ResumeLayout(false);
+ this.statusStrip.ResumeLayout(false);
+ this.statusStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
@@ -113,6 +173,11 @@ namespace ClientForm
private System.Windows.Forms.Button objectButton;
private System.Windows.Forms.Button imageButton;
private System.Windows.Forms.Button fileButton;
+ private System.Windows.Forms.TableLayoutPanel mainTablePanel;
+ private System.Windows.Forms.Panel panel1;
+ private System.Windows.Forms.StatusStrip statusStrip;
+ private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
+ private System.Windows.Forms.ToolStripStatusLabel heartBeatStatus;
}
}
diff --git a/SocketStudy/ClientForm/MainForm.cs b/SocketStudy/ClientForm/MainForm.cs
index 78efc17..173f8c8 100644
--- a/SocketStudy/ClientForm/MainForm.cs
+++ b/SocketStudy/ClientForm/MainForm.cs
@@ -144,7 +144,13 @@ namespace ClientForm
client.Connect();
heartBeatClient.Connect();
}
-
+
+ UpdateHeartBeat();
+ }
+
+ private void UpdateHeartBeat()
+ {
+ heartBeatStatus.Text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
}
private void Client_OnReceived(PClient sender, PDataType dataType, byte[] data)
diff --git a/SocketStudy/ClientForm/MainForm.resx b/SocketStudy/ClientForm/MainForm.resx
index 1af7de1..c266a2a 100644
--- a/SocketStudy/ClientForm/MainForm.resx
+++ b/SocketStudy/ClientForm/MainForm.resx
@@ -117,4 +117,7 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 21, 21
+
\ No newline at end of file
diff --git a/SocketStudy/PComm/PClient.cs b/SocketStudy/PComm/PClient.cs
index 2b1689f..2876eb7 100644
--- a/SocketStudy/PComm/PClient.cs
+++ b/SocketStudy/PComm/PClient.cs
@@ -15,7 +15,7 @@ namespace PComm
{
public class PClient
{
- private readonly int BUFF_SIZE = 1000 * 50; // 50kB
+ private readonly int BUFF_SIZE = 1000 * 1000; // 1MB
public delegate void ClientConnectedHandler(PClient sender);
public event ClientConnectedHandler OnConnected;
diff --git a/SocketStudy/ServerForm/MainForm.cs b/SocketStudy/ServerForm/MainForm.cs
new file mode 100644
index 0000000..7034b04
--- /dev/null
+++ b/SocketStudy/ServerForm/MainForm.cs
@@ -0,0 +1,153 @@
+using PComm;
+using PObject;
+using PUtility;
+using ServerForm.ChildForm;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace ServerForm
+{
+ delegate void LogHandler(PClient client, string log);
+ delegate void FormHandler(Form form);
+
+ public partial class MainForm : Form
+ {
+ private readonly int PORT = 37777;
+ private readonly int HB_PORT = 37778;
+
+ private PServer mainServer;
+ private PServer heartBeatServer;
+
+ private LogHandler logHandler;
+ private FormHandler formHandler;
+
+ private System.Timers.Timer clientCheckTimer;
+ private System.Timers.Timer GarbageTimer;
+
+ public MainForm()
+ {
+ InitializeComponent();
+ InitInstance();
+ }
+
+ private void InitInstance()
+ {
+ string path = Application.StartupPath;
+
+ heartBeatServer = new PServer(HB_PORT);
+ mainServer = new PServer(PORT);
+
+ logHandler = new LogHandler(WriteLog);
+ formHandler = new FormHandler(ShowForm);
+
+ heartBeatServer.OnDataReceived += HeartBeatServer_OnDataReceived;
+ mainServer.OnDataReceived += MainServer_OnDataReceived;
+
+ heartBeatServer.Start();
+ mainServer.Start();
+
+ clientCheckTimer = new System.Timers.Timer();
+ clientCheckTimer.Interval = 1000;
+ clientCheckTimer.Elapsed += ClientCheckTimer_Elapsed;
+ clientCheckTimer.Start();
+
+ GarbageTimer = new System.Timers.Timer();
+ GarbageTimer.Interval = 1000 * 10;
+ GarbageTimer.Elapsed += GarbageTimer_Elapsed;
+ GarbageTimer.Start();
+ }
+
+ private void WriteLog(PClient client, string log)
+ {
+ if (this.InvokeRequired)
+ {
+ this.Invoke((MethodInvoker)delegate () { WriteLog(client, log); });
+ }
+ else
+ {
+ logConsole.AppendText($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}] {client.ID}: {log}" + Environment.NewLine);
+ //PUtil.ScrollToEnd(logConsole);
+ }
+ }
+
+ private void ShowForm(Form form)
+ {
+ if (this.InvokeRequired)
+ {
+ this.Invoke((MethodInvoker)delegate () { ShowForm(form); });
+ }
+ else
+ {
+ form.Show();
+ }
+ }
+
+ private void CheckClientInfo(List clinetInfoList)
+ {
+ if (this.InvokeRequired)
+ {
+ this.Invoke((MethodInvoker)delegate () { CheckClientInfo(clinetInfoList); });
+ }
+ else
+ {
+ if (clientListBox.Items != null && clientListBox.Items.Count > 1)
+ clientListBox.Items.Clear();
+
+ foreach (PClientInfo clientInfo in clinetInfoList)
+ {
+ PClient client = clientInfo.Client;
+ string clientView = $"{client.ID}({client.EndPoint.Address}:{client.EndPoint.Port})";
+ clientListBox.Items.Add(clientView);
+ }
+ }
+ }
+
+ private void MainServer_OnDataReceived(PClientInfo sender, PDataType dataType, byte[] data)
+ {
+ DataManager.Instance.Process(sender, dataType, data, logHandler, formHandler);
+ }
+
+
+ private void HeartBeatServer_OnDataReceived(PClientInfo sender, PDataType dataType, byte[] data)
+ {
+ if (dataType != PDataType.SimpleString)
+ {
+ logHandler(sender.Client, "ERROR!!! WRONG DATA TYPE FOR HEART BEAT!!!");
+ return;
+ }
+
+ string msg = Encoding.UTF8.GetString(data, 0, data.Length);
+ if (msg != PServer.HB_CHECK)
+ logHandler(sender.Client, "WARNING!!! BAD HEARTBEAT!!!");
+
+ sender.Client.Send(PServer.HB_CHECK);
+ UpdateHeartBeat();
+ }
+
+ private void UpdateHeartBeat()
+ {
+ heartBeatStatus.Text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
+ }
+
+ private void ClientCheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
+ {
+ List clientInfoList = new List(mainServer.ClientInfoList.Count + heartBeatServer.ClientInfoList.Count);
+ clientInfoList.AddRange(mainServer.ClientInfoList);
+ clientInfoList.AddRange(heartBeatServer.ClientInfoList);
+
+ CheckClientInfo(clientInfoList);
+ }
+
+ private void GarbageTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
+ {
+ GC.Collect();
+ }
+ }
+}
diff --git a/SocketStudy/ServerForm/MainForm.resx b/SocketStudy/ServerForm/MainForm.resx
new file mode 100644
index 0000000..0fa7db7
--- /dev/null
+++ b/SocketStudy/ServerForm/MainForm.resx
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ 22, 21
+
+
\ No newline at end of file
diff --git a/SocketStudy/ServerForm/mainForm.Designer.cs b/SocketStudy/ServerForm/mainForm.Designer.cs
index 7f1358c..a84fd8f 100644
--- a/SocketStudy/ServerForm/mainForm.Designer.cs
+++ b/SocketStudy/ServerForm/mainForm.Designer.cs
@@ -31,41 +31,82 @@ namespace ServerForm
{
this.logConsole = new System.Windows.Forms.TextBox();
this.clientListBox = new System.Windows.Forms.ListBox();
+ this.mainTablePanel = new System.Windows.Forms.TableLayoutPanel();
+ this.statusStrip = new System.Windows.Forms.StatusStrip();
+ this.heartBeatStatus = new System.Windows.Forms.ToolStripStatusLabel();
+ this.mainTablePanel.SuspendLayout();
+ this.statusStrip.SuspendLayout();
this.SuspendLayout();
//
// logConsole
//
this.logConsole.BackColor = System.Drawing.Color.Black;
+ this.logConsole.Dock = System.Windows.Forms.DockStyle.Fill;
this.logConsole.ForeColor = System.Drawing.Color.SpringGreen;
- this.logConsole.Location = new System.Drawing.Point(251, 13);
+ this.logConsole.Location = new System.Drawing.Point(203, 4);
this.logConsole.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.logConsole.Multiline = true;
this.logConsole.Name = "logConsole";
this.logConsole.ScrollBars = System.Windows.Forms.ScrollBars.Both;
- this.logConsole.Size = new System.Drawing.Size(470, 364);
+ this.logConsole.Size = new System.Drawing.Size(626, 345);
this.logConsole.TabIndex = 0;
//
// clientListBox
//
+ this.clientListBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.clientListBox.FormattingEnabled = true;
this.clientListBox.ItemHeight = 15;
- this.clientListBox.Location = new System.Drawing.Point(12, 13);
+ this.clientListBox.Location = new System.Drawing.Point(3, 3);
this.clientListBox.Name = "clientListBox";
- this.clientListBox.Size = new System.Drawing.Size(233, 364);
+ this.clientListBox.Size = new System.Drawing.Size(194, 347);
this.clientListBox.TabIndex = 2;
//
+ // mainTablePanel
+ //
+ this.mainTablePanel.ColumnCount = 2;
+ this.mainTablePanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 200F));
+ this.mainTablePanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
+ this.mainTablePanel.Controls.Add(this.clientListBox, 0, 0);
+ this.mainTablePanel.Controls.Add(this.logConsole, 1, 0);
+ this.mainTablePanel.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.mainTablePanel.Location = new System.Drawing.Point(0, 0);
+ this.mainTablePanel.Name = "mainTablePanel";
+ this.mainTablePanel.RowCount = 1;
+ this.mainTablePanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
+ this.mainTablePanel.Size = new System.Drawing.Size(832, 353);
+ this.mainTablePanel.TabIndex = 3;
+ //
+ // statusStrip
+ //
+ this.statusStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
+ this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.heartBeatStatus});
+ this.statusStrip.Location = new System.Drawing.Point(0, 331);
+ this.statusStrip.Name = "statusStrip";
+ this.statusStrip.Size = new System.Drawing.Size(832, 22);
+ this.statusStrip.TabIndex = 4;
+ //
+ // heartBeatStatus
+ //
+ this.heartBeatStatus.Name = "heartBeatStatus";
+ this.heartBeatStatus.Size = new System.Drawing.Size(0, 17);
+ //
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(733, 390);
- this.Controls.Add(this.clientListBox);
- this.Controls.Add(this.logConsole);
+ this.ClientSize = new System.Drawing.Size(832, 353);
+ this.Controls.Add(this.statusStrip);
+ this.Controls.Add(this.mainTablePanel);
this.Font = new System.Drawing.Font("맑은 고딕", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "MainForm";
this.Text = "Server";
+ this.mainTablePanel.ResumeLayout(false);
+ this.mainTablePanel.PerformLayout();
+ this.statusStrip.ResumeLayout(false);
+ this.statusStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
@@ -75,6 +116,9 @@ namespace ServerForm
private System.Windows.Forms.TextBox logConsole;
private System.Windows.Forms.ListBox clientListBox;
+ private System.Windows.Forms.TableLayoutPanel mainTablePanel;
+ private System.Windows.Forms.StatusStrip statusStrip;
+ private System.Windows.Forms.ToolStripStatusLabel heartBeatStatus;
}
}