Browse Source

心跳程序未完成!!!!!! issue 1

张泳健 8 years ago
parent
commit
e024ce4d42

BIN
.vs/GWSocketClient/v15/.suo View File


+ 29 - 27
GWSocketClient/Form1.Designer.cs View File

@@ -57,8 +57,11 @@
57 57
             this.心跳HToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
58 58
             this.ToolStripMenuItemHbStart = new System.Windows.Forms.ToolStripMenuItem();
59 59
             this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
60
-            this.ToolStripMenuItemHb30 = new System.Windows.Forms.ToolStripMenuItem();
60
+            this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
61
+            this.ToolStripMenuItemHb30abc = new System.Windows.Forms.ToolStripMenuItem();
61 62
             this.toolStripTextBoxHbtime = new System.Windows.Forms.ToolStripTextBox();
63
+            this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
64
+            this.ToolStripMenuItemLogHb = new System.Windows.Forms.ToolStripMenuItem();
62 65
             this.statusStrip1 = new System.Windows.Forms.StatusStrip();
63 66
             this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
64 67
             this.tsslEquipmentAddress = new System.Windows.Forms.ToolStripStatusLabel();
@@ -69,9 +72,6 @@
69 72
             this.cmslistboxRightMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
70 73
             this.rightMenuCopyCmd = new System.Windows.Forms.ToolStripMenuItem();
71 74
             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();
75 75
             this.groupBox1.SuspendLayout();
76 76
             this.menuStrip1.SuspendLayout();
77 77
             this.statusStrip1.SuspendLayout();
@@ -344,7 +344,7 @@
344 344
             this.ToolStripMenuItemHbStart,
345 345
             this.toolStripSeparator1,
346 346
             this.toolStripSeparator3,
347
-            this.ToolStripMenuItemHb30,
347
+            this.ToolStripMenuItemHb30abc,
348 348
             this.toolStripTextBoxHbtime,
349 349
             this.toolStripSeparator2,
350 350
             this.ToolStripMenuItemLogHb});
@@ -366,11 +366,16 @@
366 366
             this.toolStripSeparator1.Name = "toolStripSeparator1";
367 367
             this.toolStripSeparator1.Size = new System.Drawing.Size(169, 6);
368 368
             // 
369
-            // ToolStripMenuItemHb30
369
+            // toolStripSeparator3
370
+            // 
371
+            this.toolStripSeparator3.Name = "toolStripSeparator3";
372
+            this.toolStripSeparator3.Size = new System.Drawing.Size(169, 6);
373
+            // 
374
+            // ToolStripMenuItemHb30abc
370 375
             // 
371
-            this.ToolStripMenuItemHb30.Name = "ToolStripMenuItemHb30";
372
-            this.ToolStripMenuItemHb30.Size = new System.Drawing.Size(172, 22);
373
-            this.ToolStripMenuItemHb30.Text = "下面输入心跳时间";
376
+            this.ToolStripMenuItemHb30abc.Name = "ToolStripMenuItemHb30abc";
377
+            this.ToolStripMenuItemHb30abc.Size = new System.Drawing.Size(172, 22);
378
+            this.ToolStripMenuItemHb30abc.Text = "下面输入心跳时间";
374 379
             // 
375 380
             // toolStripTextBoxHbtime
376 381
             // 
@@ -379,6 +384,20 @@
379 384
             this.toolStripTextBoxHbtime.Text = "5";
380 385
             this.toolStripTextBoxHbtime.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.toolStripTextBoxHbtime_KeyPress);
381 386
             // 
387
+            // toolStripSeparator2
388
+            // 
389
+            this.toolStripSeparator2.Name = "toolStripSeparator2";
390
+            this.toolStripSeparator2.Size = new System.Drawing.Size(169, 6);
391
+            // 
392
+            // ToolStripMenuItemLogHb
393
+            // 
394
+            this.ToolStripMenuItemLogHb.Checked = true;
395
+            this.ToolStripMenuItemLogHb.CheckState = System.Windows.Forms.CheckState.Checked;
396
+            this.ToolStripMenuItemLogHb.Name = "ToolStripMenuItemLogHb";
397
+            this.ToolStripMenuItemLogHb.Size = new System.Drawing.Size(172, 22);
398
+            this.ToolStripMenuItemLogHb.Text = "是否打印心跳";
399
+            this.ToolStripMenuItemLogHb.Click += new System.EventHandler(this.ToolStripMenuItemLogHb_Click);
400
+            // 
382 401
             // statusStrip1
383 402
             // 
384 403
             this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
@@ -473,23 +492,6 @@
473 492
             this.rightMenuClearInfo.Text = "清空信息(&L)";
474 493
             this.rightMenuClearInfo.Click += new System.EventHandler(this.rightMenuClearInfo_Click);
475 494
             // 
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
-            // 
493 495
             // Form1
494 496
             // 
495 497
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
@@ -559,7 +561,7 @@
559 561
         private System.Windows.Forms.ToolStripMenuItem 心跳HToolStripMenuItem;
560 562
         private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItemHbStart;
561 563
         private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
562
-        private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItemHb30;
564
+        private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItemHb30abc;
563 565
         private System.Windows.Forms.ToolStripTextBox toolStripTextBoxHbtime;
564 566
         private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
565 567
         private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;

+ 22 - 17
GWSocketClient/Form1.cs View File

@@ -35,7 +35,8 @@ namespace GWSocketClient
35 35
         private SocketHelper.TcpClients sockeTcpClients;
36 36
         private VcarecityPD vcarecityProtocolBean = null;
37 37
 
38
-        private int heartBeatInterval = 5; //心跳间隔
38
+        private int heartBeatInterval = 5; //Default 心跳间隔
39
+        private bool isStartHeartbeat = true;
39 40
 
40 41
         private void Form1_Load(object sender, EventArgs e)
41 42
         {
@@ -51,38 +52,38 @@ namespace GWSocketClient
51 52
             sockeTcpClients = new SocketHelper.TcpClients();
52 53
             ip = tbIpaddress.Text.Trim();
53 54
             port = tbPort.Text.Trim();
54
-
55
+            isStartHeartbeat = ToolStripMenuItemHbStart.Checked;
55 56
         }
56 57
 
57 58
 
58 59
         #region 处理心跳相关的
59 60
 
60
-        private void isStartHeartBeat()
61
+        private void startHeartBeat()
61 62
         {
62
-            if (ToolStripMenuItemHbStart.Checked)
63
-            {
64
-                Thread thread = new Thread(heartBeatThread);
65
-                thread.Start();
66
-            }
63
+            Thread thread = new Thread(heartBeatThread);
64
+            thread.Start();
65
+            
67 66
         }
68 67
 
69 68
         private void heartBeatThread()
70 69
         {
71
-            while (ToolStripMenuItemHbStart.Checked)
70
+            while (isStartHeartbeat)
72 71
             {
73 72
                 int interval = int.Parse(toolStripTextBoxHbtime.Text.Trim());
74 73
                 Thread.Sleep(interval * 1000);
75
-
76
-                string info = "";
77
-//                sockeTcpClients.SendData("");
78
-
74
+                string hbCmd = vcarecityProtocolBean.ProtocolStartSymbol;
75
+                hbCmd += tbEquipmentAddress.Text.Trim() + "840000";
76
+                hbCmd = Utils.calcCrcCode(hbCmd);
77
+                byte[] ts = HexUtil.hexToBytes(hbCmd);
78
+                sockeTcpClients.SendData(ts);
79 79
 
80 80
                 if (ToolStripMenuItemLogHb.Checked)
81 81
                 {
82
-                    Console.WriteLine("发送到服务端-心跳:[{0}]", info);
83
-                    addToListboxItem(string.Format("发送到服务端-心跳:[{0}]", info));
82
+                    Console.WriteLine("发送到服务端-心跳:[{0}]", hbCmd);
83
+                    addToListboxItem(string.Format("发送到服务端-心跳:[{0}]", hbCmd));
84 84
                 }
85 85
             }
86
+            addToListboxItem("心跳线程结束!");
86 87
         }
87 88
 
88 89
         #endregion
@@ -118,6 +119,8 @@ namespace GWSocketClient
118 119
                             break;
119 120
                     }
120 121
                     addToListboxItem(string.Format("客户端信息{0}", sks.ex));
122
+                    //连接成功,启动心跳线程
123
+                    startHeartBeat();
121 124
                 }
122 125
                 else
123 126
                 {
@@ -137,6 +140,7 @@ namespace GWSocketClient
137 140
                         }
138 141
                         else
139 142
                         {
143
+                            isStartHeartbeat = false;
140 144
                             addToListboxItem("状态信息:服务端主动关闭!");
141 145
                             sockeTcpClients.Stop();
142 146
                         }
@@ -277,8 +281,6 @@ namespace GWSocketClient
277 281
                 addToListboxItem(string.Format("发送到服务端:[{0}]", loginCmd));
278 282
 
279 283
                 sockeTcpClients.SendData(ts);
280
-
281
-                isStartHeartBeat();
282 284
             }
283 285
             catch (Exception ex)
284 286
             {
@@ -297,6 +299,7 @@ namespace GWSocketClient
297 299
 
298 300
         private void btnQuickLogout_Click(object sender, EventArgs e)
299 301
         {
302
+            isStartHeartbeat = false;
300 303
             try
301 304
             {
302 305
                 sockeTcpClients.Stop();
@@ -526,5 +529,7 @@ namespace GWSocketClient
526 529
         {
527 530
             ToolStripMenuItemHbStart.Checked = !ToolStripMenuItemHbStart.Checked;
528 531
         }
532
+
533
+       
529 534
     }
530 535
 }

BIN
GWSocketClient/bin/Release/dbfile/ID_INFO.accdb View File