|
@@ -27,18 +27,25 @@ namespace GWSocketClient
|
27
|
27
|
|
28
|
28
|
public partial class Form1 : Form
|
29
|
29
|
{
|
30
|
|
- public Form1()
|
31
|
|
- {
|
32
|
|
- InitializeComponent();
|
33
|
|
- }
|
|
30
|
+ #region 属性定义
|
34
|
31
|
|
35
|
32
|
private string ip;
|
36
|
33
|
private string port;
|
37
|
34
|
private SocketHelper.TcpClients sockeTcpClients;
|
|
35
|
+
|
38
|
36
|
private VcarecityPD vcarecityProtocolBean = null;
|
39
|
|
- private volatile bool hbRunFlag = false; //心跳线程标志
|
|
37
|
+
|
40
|
38
|
private ThreadFormDelegate uiDelegate;
|
41
|
39
|
|
|
40
|
+ #endregion
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+ #region Form 事件
|
|
44
|
+
|
|
45
|
+ public Form1()
|
|
46
|
+ {
|
|
47
|
+ InitializeComponent();
|
|
48
|
+ }
|
42
|
49
|
|
43
|
50
|
private void Form1_Load(object sender, EventArgs e)
|
44
|
51
|
{
|
|
@@ -60,6 +67,141 @@ namespace GWSocketClient
|
60
|
67
|
timerHeartBeat.Enabled = ToolStripMenuItemHbStart.Checked;
|
61
|
68
|
}
|
62
|
69
|
|
|
70
|
+ private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
|
71
|
+ {
|
|
72
|
+ timerHeartBeat.Enabled = false;
|
|
73
|
+ try
|
|
74
|
+ {
|
|
75
|
+ sockeTcpClients.Stop();
|
|
76
|
+ }
|
|
77
|
+ catch (Exception exception)
|
|
78
|
+ {
|
|
79
|
+ }
|
|
80
|
+ finally
|
|
81
|
+ {
|
|
82
|
+ sockeTcpClients = null;
|
|
83
|
+ }
|
|
84
|
+
|
|
85
|
+ AccsessDbLoader.getInstance().closeConnection();
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+ #endregion
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+ #region 点击事件
|
|
92
|
+
|
|
93
|
+ private void btnLogin_Click(object sender, EventArgs e)
|
|
94
|
+ {
|
|
95
|
+ try
|
|
96
|
+ {
|
|
97
|
+ if (!showTopForNoLoadXML())
|
|
98
|
+ return;
|
|
99
|
+
|
|
100
|
+ ip = tbIpaddress.Text.Trim();
|
|
101
|
+ port = tbPort.Text.Trim();
|
|
102
|
+
|
|
103
|
+ sockeTcpClients.InitSocket(ip, int.Parse(port));
|
|
104
|
+ sockeTcpClients.Start();
|
|
105
|
+ }
|
|
106
|
+ catch (Exception ex)
|
|
107
|
+ {
|
|
108
|
+ // statuslist.Items.Add(string.Format("连接失败!原因:{0}", ex.Message
|
|
109
|
+ Console.WriteLine(ex.Message);
|
|
110
|
+ }
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ private void btnQuickLogout_Click(object sender, EventArgs e)
|
|
114
|
+ {
|
|
115
|
+ try
|
|
116
|
+ {
|
|
117
|
+ sockeTcpClients.Stop();
|
|
118
|
+ }
|
|
119
|
+ catch (Exception exception)
|
|
120
|
+ {
|
|
121
|
+ addToListboxItem("你还没有登录!!" + exception.Message);
|
|
122
|
+ }
|
|
123
|
+ }
|
|
124
|
+
|
|
125
|
+ private void tsmiLoadXml_Click(object sender, EventArgs e)
|
|
126
|
+ {
|
|
127
|
+ OpenFileDialog ofd = new OpenFileDialog();
|
|
128
|
+ ofd.Filter = "XML文件|*.xml|所有文件|*.*";
|
|
129
|
+ ofd.InitialDirectory = Application.StartupPath;
|
|
130
|
+
|
|
131
|
+ if (ofd.ShowDialog() == DialogResult.OK)
|
|
132
|
+ {
|
|
133
|
+ string xmlFilepath = ofd.FileName;
|
|
134
|
+
|
|
135
|
+ vcarecityProtocolBean = new XmlLoader().load(xmlFilepath).getVcarecityPD();
|
|
136
|
+ this.Text = vcarecityProtocolBean.ProtocolName + " - " + vcarecityProtocolBean.ProtocolNo + " - " +
|
|
137
|
+ vcarecityProtocolBean.ProtocolStartSymbol;
|
|
138
|
+ }
|
|
139
|
+ }
|
|
140
|
+
|
|
141
|
+ private void btnSendData_Click(object sender, EventArgs e)
|
|
142
|
+ {
|
|
143
|
+ string trim = tfTmpSendData.Text.Trim();
|
|
144
|
+ trim = trim.Replace("\n", "").Replace("\r", "").Replace("\t", "").Replace(" ", "").Replace("-", "");
|
|
145
|
+
|
|
146
|
+ if (!trim.Equals(""))
|
|
147
|
+ {
|
|
148
|
+ byte[] ts = HexUtil.hexToBytes(trim);
|
|
149
|
+
|
|
150
|
+ addToListboxItem(string.Format("发送到服务端:[{0}]", trim));
|
|
151
|
+
|
|
152
|
+ sockeTcpClients.SendData(ts);
|
|
153
|
+ }
|
|
154
|
+ }
|
|
155
|
+
|
|
156
|
+ /// <summary>
|
|
157
|
+ /// 压力测试
|
|
158
|
+ /// </summary>
|
|
159
|
+ private void btnPressureTest_Click(object sender, EventArgs e)
|
|
160
|
+ {
|
|
161
|
+ ip = tbIpaddress.Text.Trim();
|
|
162
|
+ port = tbPort.Text.Trim();
|
|
163
|
+
|
|
164
|
+ int count = int.Parse(tbPresureTestCount.Text);
|
|
165
|
+
|
|
166
|
+ ThreadPool.QueueUserWorkItem(o =>
|
|
167
|
+ {
|
|
168
|
+ for (int i = 1024; i < 1024 + count; i++)
|
|
169
|
+ {
|
|
170
|
+ SocketHelper.TcpClients clientx = new SocketHelper.TcpClients(); //初始化类库
|
|
171
|
+ clientx.InitSocket(ip, int.Parse(port));
|
|
172
|
+ clientx.Start();
|
|
173
|
+
|
|
174
|
+ string loginCmd = "7e7e7e";
|
|
175
|
+ loginCmd += "4442832e" + i;
|
|
176
|
+ loginCmd += "820014383938363032423131393135353034373938" + i;
|
|
177
|
+ loginCmd = Utils.calcCrcCode(loginCmd);
|
|
178
|
+ sockeTcpClients.SendData(HexUtil.hexToBytes(loginCmd));
|
|
179
|
+ Thread.Sleep(200);
|
|
180
|
+ }
|
|
181
|
+ });
|
|
182
|
+ }
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+ private void buttonCmdManager_Click(object sender, EventArgs e)
|
|
186
|
+ {
|
|
187
|
+ InfoEditor ie = new InfoEditor();
|
|
188
|
+ ie.ShowDialog();
|
|
189
|
+ }
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+ private void btnTextCmd_Click(object sender, EventArgs e)
|
|
193
|
+ {
|
|
194
|
+ //beta test tool
|
|
195
|
+ if (tfTmpSendData.Text.Trim().ToLower().Equals("pre"))
|
|
196
|
+ {
|
|
197
|
+ btnPressureTest.Visible = !btnPressureTest.Visible;
|
|
198
|
+ tbPresureTestCount.Visible = !tbPresureTestCount.Visible;
|
|
199
|
+ label4.Visible = !label4.Visible;
|
|
200
|
+ }
|
|
201
|
+ }
|
|
202
|
+
|
|
203
|
+ #endregion
|
|
204
|
+
|
63
|
205
|
|
64
|
206
|
#region 处理心跳相关的
|
65
|
207
|
|
|
@@ -89,6 +231,11 @@ namespace GWSocketClient
|
89
|
231
|
}
|
90
|
232
|
}
|
91
|
233
|
|
|
234
|
+ private void ToolStripMenuItemHbStart_CheckStateChanged(object sender, EventArgs e)
|
|
235
|
+ {
|
|
236
|
+ timerHeartBeat.Enabled = ToolStripMenuItemHbStart.Checked;
|
|
237
|
+ }
|
|
238
|
+
|
92
|
239
|
#endregion
|
93
|
240
|
|
94
|
241
|
private bool showTopForNoLoadXML()
|
|
@@ -111,28 +258,28 @@ namespace GWSocketClient
|
111
|
258
|
{
|
112
|
259
|
case SocketHelper.Sockets.ErrorCodes.objectNull:
|
113
|
260
|
addToListboxItem("状态信息:服务器连接已断开");
|
114
|
|
- hbRunFlag = false;
|
115
|
261
|
checkLogin(false);
|
116
|
262
|
break;
|
117
|
263
|
case SocketHelper.Sockets.ErrorCodes.ConnectError:
|
118
|
264
|
//连接不成功
|
119
|
265
|
addToListboxItem("状态信息:连接服务器失败,可能是服务器未开启!");
|
|
266
|
+ checkLogin(false);
|
120
|
267
|
break;
|
121
|
268
|
case SocketHelper.Sockets.ErrorCodes.ConnectSuccess:
|
122
|
269
|
//连接成功
|
123
|
270
|
addToListboxItem("状态信息:与服务器连接成功");
|
124
|
271
|
addToListboxItem(string.Format("客户端信息{0}", sks.ex));
|
125
|
|
- checkLogin(true);
|
126
|
272
|
sendLoginCmd();
|
|
273
|
+ checkLogin(true);
|
|
274
|
+
|
127
|
275
|
if (StripMenuItemLoSucHb.Checked)
|
128
|
276
|
{
|
129
|
277
|
ToolStripMenuItemHbStart.Checked = true;
|
130
|
278
|
}
|
131
|
|
- hbRunFlag = true;
|
132
|
|
-// startHeartBeatThread();
|
133
|
279
|
break;
|
134
|
280
|
case SocketHelper.Sockets.ErrorCodes.TrySendData:
|
135
|
281
|
addToListboxItem("状态信息:ErrorCodes");
|
|
282
|
+ checkLogin(false);
|
136
|
283
|
break;
|
137
|
284
|
default:
|
138
|
285
|
addToListboxItem(string.Format("客户端信息{0}", sks.ex));
|
|
@@ -189,7 +336,7 @@ namespace GWSocketClient
|
189
|
336
|
|
190
|
337
|
if (!(funcode == 16 || funcode == 32))
|
191
|
338
|
{
|
192
|
|
- Console.WriteLine("功能码10进制=" + funcode + ",所以不用回复!");
|
|
339
|
+ Console.WriteLine("功能码10进制=" + funcode + ",所以不用回复! data=" + reqData);
|
193
|
340
|
return;
|
194
|
341
|
}
|
195
|
342
|
|
|
@@ -302,77 +449,21 @@ namespace GWSocketClient
|
302
|
449
|
sockeTcpClients.SendData(ts);
|
303
|
450
|
}
|
304
|
451
|
|
305
|
|
- private void btnLogin_Click(object sender, EventArgs e)
|
306
|
|
- {
|
307
|
|
- try
|
308
|
|
- {
|
309
|
|
- if (!showTopForNoLoadXML())
|
310
|
|
- return;
|
311
|
|
-
|
312
|
|
- ip = tbIpaddress.Text.Trim();
|
313
|
|
- port = tbPort.Text.Trim();
|
314
|
|
-
|
315
|
|
- sockeTcpClients.InitSocket(ip, int.Parse(port));
|
316
|
|
- sockeTcpClients.Start();
|
317
|
|
- }
|
318
|
|
- catch (Exception ex)
|
319
|
|
- {
|
320
|
|
-// statuslist.Items.Add(string.Format("连接失败!原因:{0}", ex.Message
|
321
|
|
- Console.WriteLine(ex.Message);
|
322
|
|
- }
|
323
|
|
- }
|
324
|
|
-
|
325
|
452
|
|
326
|
453
|
private void tbCCID_TextChanged(object sender, EventArgs e)
|
327
|
454
|
{
|
328
|
455
|
string ccid = tbCCID.Text.Trim();
|
329
|
|
-
|
330
|
456
|
tsslCCIDLEN.Text = ccid.Length / 2.0 + "";
|
331
|
457
|
}
|
332
|
458
|
|
333
|
|
- private void btnQuickLogout_Click(object sender, EventArgs e)
|
334
|
|
- {
|
335
|
|
- try
|
336
|
|
- {
|
337
|
|
- sockeTcpClients.Stop();
|
338
|
|
- }
|
339
|
|
- catch (Exception exception)
|
340
|
|
- {
|
341
|
|
- addToListboxItem("你还没有登录!!" + exception.Message);
|
342
|
|
- }
|
343
|
|
- }
|
344
|
|
-
|
345
|
|
- private void tsmiLoadXml_Click(object sender, EventArgs e)
|
346
|
|
- {
|
347
|
|
- OpenFileDialog ofd = new OpenFileDialog();
|
348
|
|
- ofd.Filter = "XML文件|*.xml|所有文件|*.*";
|
349
|
|
- ofd.InitialDirectory = Application.StartupPath;
|
350
|
|
-
|
351
|
|
- if (ofd.ShowDialog() == DialogResult.OK)
|
352
|
|
- {
|
353
|
|
- string xmlFilepath = ofd.FileName;
|
354
|
|
-
|
355
|
|
- vcarecityProtocolBean = new XmlLoader().load(xmlFilepath).getVcarecityPD();
|
356
|
|
- this.Text = vcarecityProtocolBean.ProtocolName + " - " + vcarecityProtocolBean.ProtocolNo + " - " +
|
357
|
|
- vcarecityProtocolBean.ProtocolStartSymbol;
|
358
|
|
- }
|
359
|
|
- }
|
360
|
|
-
|
361
|
|
- private void btnSendData_Click(object sender, EventArgs e)
|
362
|
|
- {
|
363
|
|
- string trim = tfTmpSendData.Text.Trim();
|
364
|
|
- trim = trim.Replace("\n", "").Replace("\r", "").Replace("\t", "").Replace(" ", "").Replace("-", "");
|
365
|
|
-
|
366
|
|
- if (!trim.Equals(""))
|
367
|
|
- {
|
368
|
|
- byte[] ts = HexUtil.hexToBytes(trim);
|
369
|
|
-
|
370
|
|
- addToListboxItem(string.Format("发送到服务端:[{0}]", trim));
|
371
|
459
|
|
372
|
|
- sockeTcpClients.SendData(ts);
|
373
|
|
- }
|
374
|
|
- }
|
|
460
|
+ #region ListBox相关
|
375
|
461
|
|
|
462
|
+ /// <summary>
|
|
463
|
+ /// ListBox右键菜单-点击复制
|
|
464
|
+ /// </summary>
|
|
465
|
+ /// <param name="sender"></param>
|
|
466
|
+ /// <param name="e"></param>
|
376
|
467
|
private void rightMenuCopyCmd_Click(object sender, EventArgs e)
|
377
|
468
|
{
|
378
|
469
|
int index = listBoxShow.SelectedIndex;
|
|
@@ -404,13 +495,12 @@ namespace GWSocketClient
|
404
|
495
|
}
|
405
|
496
|
}
|
406
|
497
|
|
407
|
|
-
|
408
|
498
|
private void addToListboxItem(object info)
|
409
|
499
|
{
|
410
|
500
|
if (listBoxShow.Items.Count > 1000)
|
411
|
501
|
{
|
412
|
502
|
listBoxShow.Items.Remove(0);
|
413
|
|
-// listBoxShow.Items.Clear();
|
|
503
|
+ // listBoxShow.Items.Clear();
|
414
|
504
|
}
|
415
|
505
|
|
416
|
506
|
Console.WriteLine(info);
|
|
@@ -418,7 +508,6 @@ namespace GWSocketClient
|
418
|
508
|
listBoxShow.TopIndex = listBoxShow.Items.Count - 1;
|
419
|
509
|
}
|
420
|
510
|
|
421
|
|
-
|
422
|
511
|
private void rightMenuClearInfo_Click(object sender, EventArgs e)
|
423
|
512
|
{
|
424
|
513
|
listBoxShow.Items.Clear();
|
|
@@ -461,34 +550,6 @@ namespace GWSocketClient
|
461
|
550
|
}
|
462
|
551
|
}
|
463
|
552
|
|
464
|
|
- /// <summary>
|
465
|
|
- /// 压力测试
|
466
|
|
- /// </summary>
|
467
|
|
- private void btnPressureTest_Click(object sender, EventArgs e)
|
468
|
|
- {
|
469
|
|
- ip = tbIpaddress.Text.Trim();
|
470
|
|
- port = tbPort.Text.Trim();
|
471
|
|
-
|
472
|
|
- int count = int.Parse(tbPresureTestCount.Text);
|
473
|
|
-
|
474
|
|
- ThreadPool.QueueUserWorkItem(o =>
|
475
|
|
- {
|
476
|
|
- for (int i = 1024; i < 1024 + count; i++)
|
477
|
|
- {
|
478
|
|
- SocketHelper.TcpClients clientx = new SocketHelper.TcpClients(); //初始化类库
|
479
|
|
- clientx.InitSocket(ip, int.Parse(port));
|
480
|
|
- clientx.Start();
|
481
|
|
-
|
482
|
|
- string loginCmd = "7e7e7e";
|
483
|
|
- loginCmd += "4442832e" + i;
|
484
|
|
- loginCmd += "820014383938363032423131393135353034373938" + i;
|
485
|
|
- loginCmd = Utils.calcCrcCode(loginCmd);
|
486
|
|
- sockeTcpClients.SendData(HexUtil.hexToBytes(loginCmd));
|
487
|
|
- Thread.Sleep(200);
|
488
|
|
- }
|
489
|
|
- });
|
490
|
|
- }
|
491
|
|
-
|
492
|
553
|
private void listBoxShow_DoubleClick(object sender, EventArgs e)
|
493
|
554
|
{
|
494
|
555
|
int index = listBoxShow.SelectedIndex;
|
|
@@ -505,7 +566,7 @@ namespace GWSocketClient
|
505
|
566
|
ifs = ifs.Replace("[", "").Replace("]", "");
|
506
|
567
|
if (!info.Equals(""))
|
507
|
568
|
{
|
508
|
|
-// MessageBox.Show(ifs);
|
|
569
|
+ // MessageBox.Show(ifs);
|
509
|
570
|
AnaProtocol ap = new AnaProtocol(ifs);
|
510
|
571
|
ap.ShowDialog();
|
511
|
572
|
}
|
|
@@ -514,59 +575,10 @@ namespace GWSocketClient
|
514
|
575
|
}
|
515
|
576
|
}
|
516
|
577
|
|
517
|
|
- private void buttonCmdManager_Click(object sender, EventArgs e)
|
518
|
|
- {
|
519
|
|
- InfoEditor ie = new InfoEditor();
|
520
|
|
- ie.ShowDialog();
|
521
|
|
- }
|
522
|
|
-
|
523
|
|
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
524
|
|
- {
|
525
|
|
- timerHeartBeat.Enabled = false;
|
526
|
|
- try
|
527
|
|
- {
|
528
|
|
- sockeTcpClients.Stop();
|
529
|
|
- }
|
530
|
|
- catch (Exception exception)
|
531
|
|
- {
|
532
|
|
- }
|
533
|
|
- finally
|
534
|
|
- {
|
535
|
|
- sockeTcpClients = null;
|
536
|
|
- }
|
537
|
|
-
|
538
|
|
- AccsessDbLoader.getInstance().closeConnection();
|
539
|
|
- }
|
540
|
|
-
|
541
|
|
- private void btnTextCmd_Click(object sender, EventArgs e)
|
542
|
|
- {
|
543
|
|
- //beta test tool
|
544
|
|
- if (tfTmpSendData.Text.Trim().ToLower().Equals("pre"))
|
545
|
|
- {
|
546
|
|
- btnPressureTest.Visible = !btnPressureTest.Visible;
|
547
|
|
- tbPresureTestCount.Visible = !tbPresureTestCount.Visible;
|
548
|
|
- label4.Visible = !label4.Visible;
|
549
|
|
- }
|
550
|
|
-
|
551
|
|
-// string code = Utils.calcCrcCode("7e7e7e123456789abc20000701010107030001");
|
552
|
|
-// code = Utils.calcCrcCode("7e7e7e123456789abc10000501010107023f");
|
553
|
|
-// Console.WriteLine(code);
|
554
|
|
-
|
555
|
|
-// handleResponse(null, code);
|
|
578
|
+ #endregion
|
556
|
579
|
|
557
|
580
|
|
558
|
|
- /*try
|
559
|
|
- {
|
560
|
|
- Dictionary<string, string> abc = AccsessDbLoader.getInstance().getUserIdInfo();
|
561
|
|
- MessageBox.Show(abc.Count + "");
|
562
|
|
- string ac = abc["0400"];
|
563
|
|
- MessageBox.Show(ac);
|
564
|
|
- }
|
565
|
|
- catch (Exception exception)
|
566
|
|
- {
|
567
|
|
- Console.WriteLine(exception);
|
568
|
|
- }*/
|
569
|
|
- }
|
|
581
|
+ #region 检验工具类
|
570
|
582
|
|
571
|
583
|
private void toolStripTextBoxHbtime_KeyPress(object sender, KeyPressEventArgs e)
|
572
|
584
|
{
|
|
@@ -576,11 +588,6 @@ namespace GWSocketClient
|
576
|
588
|
}
|
577
|
589
|
}
|
578
|
590
|
|
579
|
|
- private void ToolStripMenuItemLogHb_Click(object sender, EventArgs e)
|
580
|
|
- {
|
581
|
|
- ToolStripMenuItemLogHb.Checked = !ToolStripMenuItemLogHb.Checked;
|
582
|
|
- }
|
583
|
|
-
|
584
|
591
|
|
585
|
592
|
private void checkLogin(bool isLogin)
|
586
|
593
|
{
|
|
@@ -589,24 +596,24 @@ namespace GWSocketClient
|
589
|
596
|
btnLogin.Enabled = false;
|
590
|
597
|
btnQuickLogout.Enabled = true;
|
591
|
598
|
btnSendData.Enabled = true;
|
592
|
|
- ToolStripMenuItemHbStart.Enabled = true;
|
|
599
|
+ ToolStripMenuItemHbStart.Enabled = true; //开启心中的点击选项
|
|
600
|
+ if (StripMenuItemLoSucHb.Checked)
|
|
601
|
+ {
|
|
602
|
+ //如果勾选了登录成功并心跳
|
|
603
|
+ timerHeartBeat.Enabled = true;
|
|
604
|
+ }
|
593
|
605
|
}
|
594
|
606
|
else
|
595
|
607
|
{
|
596
|
608
|
btnLogin.Enabled = true;
|
597
|
609
|
btnQuickLogout.Enabled = false;
|
598
|
610
|
btnSendData.Enabled = false;
|
|
611
|
+ ToolStripMenuItemHbStart.Checked = false;
|
599
|
612
|
ToolStripMenuItemHbStart.Enabled = false;
|
|
613
|
+ timerHeartBeat.Enabled = false;
|
600
|
614
|
}
|
601
|
615
|
}
|
602
|
616
|
|
603
|
|
- private void ToolStripMenuItemHbStart_CheckStateChanged(object sender, EventArgs e)
|
604
|
|
- {
|
605
|
|
- timerHeartBeat.Enabled = ToolStripMenuItemHbStart.Checked;
|
606
|
|
- }
|
607
|
|
-
|
608
|
|
- private void ToolStripMenuItemHbStart_Click(object sender, EventArgs e)
|
609
|
|
- {
|
610
|
|
- }
|
|
617
|
+ #endregion
|
611
|
618
|
}
|
612
|
619
|
}
|