瀏覽代碼

添加心跳,但未完成!!!

张泳健 8 年之前
父節點
當前提交
a2c4eb4448
共有 4 個文件被更改,包括 133 次插入2 次删除
  1. 二進制
      .vs/GWSocketClient/v15/.suo
  2. 76 1
      GWSocketClient/Form1.Designer.cs
  3. 56 0
      GWSocketClient/Form1.cs
  4. 1 1
      GWSocketClient/GWSocketClient.csproj

二進制
.vs/GWSocketClient/v15/.suo 查看文件


+ 76 - 1
GWSocketClient/Form1.Designer.cs 查看文件

54
             this.menuStrip1 = new System.Windows.Forms.MenuStrip();
54
             this.menuStrip1 = new System.Windows.Forms.MenuStrip();
55
             this.文件FToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
55
             this.文件FToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
56
             this.tsmiLoadXml = new System.Windows.Forms.ToolStripMenuItem();
56
             this.tsmiLoadXml = new System.Windows.Forms.ToolStripMenuItem();
57
+            this.心跳HToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
58
+            this.ToolStripMenuItemHbStart = new System.Windows.Forms.ToolStripMenuItem();
59
+            this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
60
+            this.ToolStripMenuItemHb30 = new System.Windows.Forms.ToolStripMenuItem();
61
+            this.toolStripTextBoxHbtime = new System.Windows.Forms.ToolStripTextBox();
57
             this.statusStrip1 = new System.Windows.Forms.StatusStrip();
62
             this.statusStrip1 = new System.Windows.Forms.StatusStrip();
58
             this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
63
             this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
59
             this.tsslEquipmentAddress = new System.Windows.Forms.ToolStripStatusLabel();
64
             this.tsslEquipmentAddress = new System.Windows.Forms.ToolStripStatusLabel();
64
             this.cmslistboxRightMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
69
             this.cmslistboxRightMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
65
             this.rightMenuCopyCmd = new System.Windows.Forms.ToolStripMenuItem();
70
             this.rightMenuCopyCmd = new System.Windows.Forms.ToolStripMenuItem();
66
             this.rightMenuClearInfo = new System.Windows.Forms.ToolStripMenuItem();
71
             this.rightMenuClearInfo = new System.Windows.Forms.ToolStripMenuItem();
72
+            this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
73
+            this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
74
+            this.ToolStripMenuItemLogHb = new System.Windows.Forms.ToolStripMenuItem();
67
             this.groupBox1.SuspendLayout();
75
             this.groupBox1.SuspendLayout();
68
             this.menuStrip1.SuspendLayout();
76
             this.menuStrip1.SuspendLayout();
69
             this.statusStrip1.SuspendLayout();
77
             this.statusStrip1.SuspendLayout();
306
             // menuStrip1
314
             // menuStrip1
307
             // 
315
             // 
308
             this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
316
             this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
309
-            this.文件FToolStripMenuItem});
317
+            this.文件FToolStripMenuItem,
318
+            this.心跳HToolStripMenuItem});
310
             this.menuStrip1.Location = new System.Drawing.Point(0, 0);
319
             this.menuStrip1.Location = new System.Drawing.Point(0, 0);
311
             this.menuStrip1.Name = "menuStrip1";
320
             this.menuStrip1.Name = "menuStrip1";
312
             this.menuStrip1.Padding = new System.Windows.Forms.Padding(7, 3, 0, 3);
321
             this.menuStrip1.Padding = new System.Windows.Forms.Padding(7, 3, 0, 3);
329
             this.tsmiLoadXml.Text = "加载协议XML(&X)";
338
             this.tsmiLoadXml.Text = "加载协议XML(&X)";
330
             this.tsmiLoadXml.Click += new System.EventHandler(this.tsmiLoadXml_Click);
339
             this.tsmiLoadXml.Click += new System.EventHandler(this.tsmiLoadXml_Click);
331
             // 
340
             // 
341
+            // 心跳HToolStripMenuItem
342
+            // 
343
+            this.心跳HToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
344
+            this.ToolStripMenuItemHbStart,
345
+            this.toolStripSeparator1,
346
+            this.toolStripSeparator3,
347
+            this.ToolStripMenuItemHb30,
348
+            this.toolStripTextBoxHbtime,
349
+            this.toolStripSeparator2,
350
+            this.ToolStripMenuItemLogHb});
351
+            this.心跳HToolStripMenuItem.Name = "心跳HToolStripMenuItem";
352
+            this.心跳HToolStripMenuItem.Size = new System.Drawing.Size(61, 21);
353
+            this.心跳HToolStripMenuItem.Text = "心跳(&H)";
354
+            // 
355
+            // ToolStripMenuItemHbStart
356
+            // 
357
+            this.ToolStripMenuItemHbStart.Checked = true;
358
+            this.ToolStripMenuItemHbStart.CheckState = System.Windows.Forms.CheckState.Checked;
359
+            this.ToolStripMenuItemHbStart.Name = "ToolStripMenuItemHbStart";
360
+            this.ToolStripMenuItemHbStart.Size = new System.Drawing.Size(172, 22);
361
+            this.ToolStripMenuItemHbStart.Text = "登录成功就开启";
362
+            this.ToolStripMenuItemHbStart.Click += new System.EventHandler(this.ToolStripMenuItemHbStart_Click);
363
+            // 
364
+            // toolStripSeparator1
365
+            // 
366
+            this.toolStripSeparator1.Name = "toolStripSeparator1";
367
+            this.toolStripSeparator1.Size = new System.Drawing.Size(169, 6);
368
+            // 
369
+            // ToolStripMenuItemHb30
370
+            // 
371
+            this.ToolStripMenuItemHb30.Name = "ToolStripMenuItemHb30";
372
+            this.ToolStripMenuItemHb30.Size = new System.Drawing.Size(172, 22);
373
+            this.ToolStripMenuItemHb30.Text = "下面输入心跳时间";
374
+            // 
375
+            // toolStripTextBoxHbtime
376
+            // 
377
+            this.toolStripTextBoxHbtime.Name = "toolStripTextBoxHbtime";
378
+            this.toolStripTextBoxHbtime.Size = new System.Drawing.Size(100, 23);
379
+            this.toolStripTextBoxHbtime.Text = "5";
380
+            this.toolStripTextBoxHbtime.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.toolStripTextBoxHbtime_KeyPress);
381
+            // 
332
             // statusStrip1
382
             // statusStrip1
333
             // 
383
             // 
334
             this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
384
             this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
423
             this.rightMenuClearInfo.Text = "清空信息(&L)";
473
             this.rightMenuClearInfo.Text = "清空信息(&L)";
424
             this.rightMenuClearInfo.Click += new System.EventHandler(this.rightMenuClearInfo_Click);
474
             this.rightMenuClearInfo.Click += new System.EventHandler(this.rightMenuClearInfo_Click);
425
             // 
475
             // 
476
+            // toolStripSeparator2
477
+            // 
478
+            this.toolStripSeparator2.Name = "toolStripSeparator2";
479
+            this.toolStripSeparator2.Size = new System.Drawing.Size(169, 6);
480
+            // 
481
+            // toolStripSeparator3
482
+            // 
483
+            this.toolStripSeparator3.Name = "toolStripSeparator3";
484
+            this.toolStripSeparator3.Size = new System.Drawing.Size(169, 6);
485
+            // 
486
+            // ToolStripMenuItemLogHb
487
+            // 
488
+            this.ToolStripMenuItemLogHb.Name = "ToolStripMenuItemLogHb";
489
+            this.ToolStripMenuItemLogHb.Size = new System.Drawing.Size(172, 22);
490
+            this.ToolStripMenuItemLogHb.Text = "是否打印心跳";
491
+            this.ToolStripMenuItemLogHb.Click += new System.EventHandler(this.ToolStripMenuItemLogHb_Click);
492
+            // 
426
             // Form1
493
             // Form1
427
             // 
494
             // 
428
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
495
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
489
         private System.Windows.Forms.ToolStripMenuItem rightMenuClearInfo;
556
         private System.Windows.Forms.ToolStripMenuItem rightMenuClearInfo;
490
         private System.Windows.Forms.Button buttonCmdManager;
557
         private System.Windows.Forms.Button buttonCmdManager;
491
         private System.Windows.Forms.Button btnTextCmd;
558
         private System.Windows.Forms.Button btnTextCmd;
559
+        private System.Windows.Forms.ToolStripMenuItem 心跳HToolStripMenuItem;
560
+        private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItemHbStart;
561
+        private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
562
+        private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItemHb30;
563
+        private System.Windows.Forms.ToolStripTextBox toolStripTextBoxHbtime;
564
+        private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
565
+        private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
566
+        private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItemLogHb;
492
     }
567
     }
493
 }
568
 }
494
 
569
 

+ 56 - 0
GWSocketClient/Form1.cs 查看文件

35
         private SocketHelper.TcpClients sockeTcpClients;
35
         private SocketHelper.TcpClients sockeTcpClients;
36
         private VcarecityPD vcarecityProtocolBean = null;
36
         private VcarecityPD vcarecityProtocolBean = null;
37
 
37
 
38
+        private int heartBeatInterval = 5; //心跳间隔
39
+
38
         private void Form1_Load(object sender, EventArgs e)
40
         private void Form1_Load(object sender, EventArgs e)
39
         {
41
         {
40
             XmlLoader xmlLoader = new XmlLoader();
42
             XmlLoader xmlLoader = new XmlLoader();
49
             sockeTcpClients = new SocketHelper.TcpClients();
51
             sockeTcpClients = new SocketHelper.TcpClients();
50
             ip = tbIpaddress.Text.Trim();
52
             ip = tbIpaddress.Text.Trim();
51
             port = tbPort.Text.Trim();
53
             port = tbPort.Text.Trim();
54
+
55
+        }
56
+
57
+
58
+        #region 处理心跳相关的
59
+
60
+        private void isStartHeartBeat()
61
+        {
62
+            if (ToolStripMenuItemHbStart.Checked)
63
+            {
64
+                Thread thread = new Thread(heartBeatThread);
65
+                thread.Start();
66
+            }
67
+        }
68
+
69
+        private void heartBeatThread()
70
+        {
71
+            while (ToolStripMenuItemHbStart.Checked)
72
+            {
73
+                int interval = int.Parse(toolStripTextBoxHbtime.Text.Trim());
74
+                Thread.Sleep(interval * 1000);
75
+
76
+                string info = "";
77
+//                sockeTcpClients.SendData("");
78
+
79
+
80
+                if (ToolStripMenuItemLogHb.Checked)
81
+                {
82
+                    Console.WriteLine("发送到服务端-心跳:[{0}]", info);
83
+                    addToListboxItem(string.Format("发送到服务端-心跳:[{0}]", info));
84
+                }
85
+            }
52
         }
86
         }
53
 
87
 
88
+        #endregion
89
+
54
         private bool showTopForNoLoadXML()
90
         private bool showTopForNoLoadXML()
55
         {
91
         {
56
             if (vcarecityProtocolBean == null)
92
             if (vcarecityProtocolBean == null)
241
                 addToListboxItem(string.Format("发送到服务端:[{0}]", loginCmd));
277
                 addToListboxItem(string.Format("发送到服务端:[{0}]", loginCmd));
242
 
278
 
243
                 sockeTcpClients.SendData(ts);
279
                 sockeTcpClients.SendData(ts);
280
+
281
+                isStartHeartBeat();
244
             }
282
             }
245
             catch (Exception ex)
283
             catch (Exception ex)
246
             {
284
             {
470
                 Console.WriteLine(exception);
508
                 Console.WriteLine(exception);
471
             }*/
509
             }*/
472
         }
510
         }
511
+
512
+        private void toolStripTextBoxHbtime_KeyPress(object sender, KeyPressEventArgs e)
513
+        {
514
+            if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
515
+            {
516
+                e.Handled = true;
517
+            }
518
+        }
519
+
520
+        private void ToolStripMenuItemLogHb_Click(object sender, EventArgs e)
521
+        {
522
+            ToolStripMenuItemLogHb.Checked = !ToolStripMenuItemLogHb.Checked;
523
+        }
524
+
525
+        private void ToolStripMenuItemHbStart_Click(object sender, EventArgs e)
526
+        {
527
+            ToolStripMenuItemHbStart.Checked = !ToolStripMenuItemHbStart.Checked;
528
+        }
473
     }
529
     }
474
 }
530
 }

+ 1 - 1
GWSocketClient/GWSocketClient.csproj 查看文件

5
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7
     <ProjectGuid>{1E7C256A-9CA5-4937-A5DD-7F281A2EBB21}</ProjectGuid>
7
     <ProjectGuid>{1E7C256A-9CA5-4937-A5DD-7F281A2EBB21}</ProjectGuid>
8
-    <OutputType>WinExe</OutputType>
8
+    <OutputType>Exe</OutputType>
9
     <RootNamespace>GWSocketClient</RootNamespace>
9
     <RootNamespace>GWSocketClient</RootNamespace>
10
     <AssemblyName>GWSocketClient</AssemblyName>
10
     <AssemblyName>GWSocketClient</AssemblyName>
11
     <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
11
     <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>