张泳健 7 vuotta sitten
vanhempi
commit
7533c53b05

+ 1 - 1
DotNettyFrom/Form1.cs Näytä tiedosto

58
 
58
 
59
         private void BtnSendData_Click(object sender, EventArgs e)
59
         private void BtnSendData_Click(object sender, EventArgs e)
60
         {
60
         {
61
-            nc.SendData("");
61
+            nc?.SendData("");
62
         }
62
         }
63
     }
63
     }
64
 }
64
 }

+ 1 - 1
DotNettyFrom/common/UIInfoModel..cs Näytä tiedosto

10
     [Serializable]
10
     [Serializable]
11
     public class UIInfoModel
11
     public class UIInfoModel
12
     {
12
     {
13
-        public int action = -1;
13
+        public int action = int.MinValue;
14
         public DateTime time = DateTime.Now;
14
         public DateTime time = DateTime.Now;
15
         public string info = "";
15
         public string info = "";
16
 
16
 

+ 9 - 9
DotNettyFrom/netty/NettyClient.cs Näytä tiedosto

25
         {
25
         {
26
             IPAddress hostIp = IPAddress.Parse(host);
26
             IPAddress hostIp = IPAddress.Parse(host);
27
             RunClientAsync(hostIp, port);
27
             RunClientAsync(hostIp, port);
28
+            DataModel.ReceCollection.Add(new UIInfoModel("开启连接"));
28
         }
29
         }
29
 
30
 
30
         private async void RunClientAsync(IPAddress HostIP, int Port)
31
         private async void RunClientAsync(IPAddress HostIP, int Port)
50
             catch (Exception e)
51
             catch (Exception e)
51
             {
52
             {
52
                 //连接出错,服务器没开启....
53
                 //连接出错,服务器没开启....
53
-                Console.WriteLine(e);
54
+                //Console.WriteLine(e);
55
+                DataModel.ReceCollection.Add(new UIInfoModel("远程服务器连接失败").setAction(-1));
54
                 await _group.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));
56
                 await _group.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));
55
             }
57
             }
56
-            
57
         }
58
         }
58
 
59
 
59
 
60
 
65
                 byte[] messageBytes = Encoding.UTF8.GetBytes(DateTime.Now.ToLongDateString());
66
                 byte[] messageBytes = Encoding.UTF8.GetBytes(DateTime.Now.ToLongDateString());
66
                 msg.WriteBytes(messageBytes);
67
                 msg.WriteBytes(messageBytes);
67
                 Context.Channel.WriteAndFlushAsync(msg);
68
                 Context.Channel.WriteAndFlushAsync(msg);
69
+                DataModel.ReceCollection.Add(new UIInfoModel("发送", hex).setIsSend(true));
68
             }
70
             }
69
             else
71
             else
70
             {
72
             {
71
-                DataModel.ReceCollection.Add(new UIInfoModel("连接已断开", ""));
73
+                DataModel.ReceCollection.Add(new UIInfoModel("连接已断开"));
72
             }
74
             }
73
         }
75
         }
74
 
76
 
80
             _group = null;
82
             _group = null;
81
             Context = null;
83
             Context = null;
82
             _clientHandler = null;
84
             _clientHandler = null;
85
+            DataModel.ReceCollection.Add(new UIInfoModel("停止连接"));
83
         }
86
         }
84
 
87
 
85
 
88
 
88
             public override void ChannelActive(IChannelHandlerContext context)
91
             public override void ChannelActive(IChannelHandlerContext context)
89
             {
92
             {
90
                 Context = context;
93
                 Context = context;
91
-
92
-
93
                 IByteBuffer msg = Unpooled.Buffer(128);
94
                 IByteBuffer msg = Unpooled.Buffer(128);
94
                 byte[] messageBytes = Encoding.UTF8.GetBytes(DateTime.Now.ToLongDateString());
95
                 byte[] messageBytes = Encoding.UTF8.GetBytes(DateTime.Now.ToLongDateString());
95
                 msg.WriteBytes(messageBytes);
96
                 msg.WriteBytes(messageBytes);
96
                 context.WriteAndFlushAsync(msg);
97
                 context.WriteAndFlushAsync(msg);
97
-
98
-                DataModel.ReceCollection.Add(new UIInfoModel("", DateTime.Now.ToLongDateString() + "channeiActive"));
98
+                DataModel.ReceCollection.Add(new UIInfoModel("连接成功").setAction(1));
99
             }
99
             }
100
 
100
 
101
 
101
 
128
             {
128
             {
129
                 base.ExceptionCaught(context, exception);
129
                 base.ExceptionCaught(context, exception);
130
                 Console.WriteLine(exception.Message);
130
                 Console.WriteLine(exception.Message);
131
-                DataModel.ReceCollection.Add(new UIInfoModel("", "ExceptionCaught:" + exception.Message));
131
+                DataModel.ReceCollection.Add(new UIInfoModel("", "ExceptionCaught:" + exception.Message).setAction(3));
132
             }
132
             }
133
 
133
 
134
             public override void ChannelInactive(IChannelHandlerContext context)
134
             public override void ChannelInactive(IChannelHandlerContext context)
135
             {
135
             {
136
                 base.ChannelInactive(context);
136
                 base.ChannelInactive(context);
137
-                DataModel.ReceCollection.Add(new UIInfoModel("", "ChannelInactive"));
137
+                DataModel.ReceCollection.Add(new UIInfoModel("", "ChannelInactive").setAction(2));
138
             }
138
             }
139
         }
139
         }
140
     }
140
     }