|
@@ -25,6 +25,7 @@ namespace DotNettyFrom.netty
|
25
|
25
|
{
|
26
|
26
|
IPAddress hostIp = IPAddress.Parse(host);
|
27
|
27
|
RunClientAsync(hostIp, port);
|
|
28
|
+ DataModel.ReceCollection.Add(new UIInfoModel("开启连接"));
|
28
|
29
|
}
|
29
|
30
|
|
30
|
31
|
private async void RunClientAsync(IPAddress HostIP, int Port)
|
|
@@ -50,10 +51,10 @@ namespace DotNettyFrom.netty
|
50
|
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
|
56
|
await _group.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));
|
55
|
57
|
}
|
56
|
|
-
|
57
|
58
|
}
|
58
|
59
|
|
59
|
60
|
|
|
@@ -65,10 +66,11 @@ namespace DotNettyFrom.netty
|
65
|
66
|
byte[] messageBytes = Encoding.UTF8.GetBytes(DateTime.Now.ToLongDateString());
|
66
|
67
|
msg.WriteBytes(messageBytes);
|
67
|
68
|
Context.Channel.WriteAndFlushAsync(msg);
|
|
69
|
+ DataModel.ReceCollection.Add(new UIInfoModel("发送", hex).setIsSend(true));
|
68
|
70
|
}
|
69
|
71
|
else
|
70
|
72
|
{
|
71
|
|
- DataModel.ReceCollection.Add(new UIInfoModel("连接已断开", ""));
|
|
73
|
+ DataModel.ReceCollection.Add(new UIInfoModel("连接已经断开"));
|
72
|
74
|
}
|
73
|
75
|
}
|
74
|
76
|
|
|
@@ -80,6 +82,7 @@ namespace DotNettyFrom.netty
|
80
|
82
|
_group = null;
|
81
|
83
|
Context = null;
|
82
|
84
|
_clientHandler = null;
|
|
85
|
+ DataModel.ReceCollection.Add(new UIInfoModel("停止连接"));
|
83
|
86
|
}
|
84
|
87
|
|
85
|
88
|
|
|
@@ -88,14 +91,11 @@ namespace DotNettyFrom.netty
|
88
|
91
|
public override void ChannelActive(IChannelHandlerContext context)
|
89
|
92
|
{
|
90
|
93
|
Context = context;
|
91
|
|
-
|
92
|
|
-
|
93
|
94
|
IByteBuffer msg = Unpooled.Buffer(128);
|
94
|
95
|
byte[] messageBytes = Encoding.UTF8.GetBytes(DateTime.Now.ToLongDateString());
|
95
|
96
|
msg.WriteBytes(messageBytes);
|
96
|
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,13 +128,13 @@ namespace DotNettyFrom.netty
|
128
|
128
|
{
|
129
|
129
|
base.ExceptionCaught(context, exception);
|
130
|
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
|
134
|
public override void ChannelInactive(IChannelHandlerContext context)
|
135
|
135
|
{
|
136
|
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
|
}
|