- 浏览: 24869 次
- 性别:
- 来自: 深圳
-
文章分类
- 全部博客 (18)
- Ajax+DWR (0)
- CallCenter+Asterisk (0)
- EJB+RMI (0)
- Hadoop并行计算 (0)
- HTML+CSS (0)
- J2EE (0)
- Java基础 (2)
- JMS (0)
- JS+jQuery (2)
- JSF (0)
- Linux+Shell+Python (0)
- NoSQL+MongoDB+Cassandra (0)
- Spider+Lucene+solr+nutch (2)
- Spring (0)
- SQL+MySQL (0)
- Web Service+Hessian (0)
- 个人生活 (0)
- 其他 (0)
- 学习心得 (1)
- 工作感悟 (5)
- 服务器+Tomcat+Jetty (0)
- 缓存+Memcached+Redis (1)
- 网络开发+Mina+Netty (3)
- 设计模式 (2)
- 重构 (0)
最新评论
-
xuzhou530:
为什么int length = buffer.readInt( ...
使用Netty实现通用二进制协议的高效数据传输 -
xuzhou530:
我使用你上面的代码启动服务端没有问题,启动客户端出现了下面问题 ...
使用Netty实现通用二进制协议的高效数据传输 -
xuzhou530:
哦哦,谢谢,了
使用Netty实现通用二进制协议的高效数据传输 -
drager:
<div class="quote_title ...
使用Netty实现通用二进制协议的高效数据传输 -
xuzhou530:
XLCharSetFactory这个类没有呀,这个类干嘛的
使用Netty实现通用二进制协议的高效数据传输
Netty是一个高性能的NIO通信框架,提供异步的、事件驱动的网络编程模型。使用Netty可以方便用户开发各种常用协议的网络程序。例如:TCP、UDP、HTTP等等。
Netty的最新版本是3.2.7,官网地址是:http://www.jboss.org/netty
本文的主要目的是基于Netty实现一个通用二进制协议的高效数据传输。协议是通用的二进制协议,高效并且扩展性很好。
一个好的协议有两个标准:
(1)生成的传输数据要少,即数据压缩比要高。这样可以减少网络开销。
(2)传输数据和业务对象之间的转换速度要快。
(友情提示:本博文章欢迎转载,但请注明出处:hankchen,http://www.blogjava.net/hankchen)
一、协议的定义
无论是请求还是响应,报文都由一个通用报文头和实际数据组成。报文头在前,数据在后。
(1)报文头:由数据解析类型,数据解析方法,编码,扩展字节,包长度组成,共16个字节:
编码方式(1byte)、加密(1byte)、扩展1(1byte)、扩展2(1byte)、会话ID(4byte)、命令或者结果码(4byte)、数据包长(4byte)
(2)数据:由数据包长指定。请求或回复数据。类型对应为JAVA的Map<String,String>
数据格式定义:
字段1键名长度 字段1键名 字段1值长度 字段1值
字段2键名长度 字段2键名 字段2值长度 字段2值
字段3键名长度 字段3键名 字段3值长度 字段3值
… … … …
长度为整型,占4个字节
代码中用两个Vo对象来表示:XLRequest和XLResponse。
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
2
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
3
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
4
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
5
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
6
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
7
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
10
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
11
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
12
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
13
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
14
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
15
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
16
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
17
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
18
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
19
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
20
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
21
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
22
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
23
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
24
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
25
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
26
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
27
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
28
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
29
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
30
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
31
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
32
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
33
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
34
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
35
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
36
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
37
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
38
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
39
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
40
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
41
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
42
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
43
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
44
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
45
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
46
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
47
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
48
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
49
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
50
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
51
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
52
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
53
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
54
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
55
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
56
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
57
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
58
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
59
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
60
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
61
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
62
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
63
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
64
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
65
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
66
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
67
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
68
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
69
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
70
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
71
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
72
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
73
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
74
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
75
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
76
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
77
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
78
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
79
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
80
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
81
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
82
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
83
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
84
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
85
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
86
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
87
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
88
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
89
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
90
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
91
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
92
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
93
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
94
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
95
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
96
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
97
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
98
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
99
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
100
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
101
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
102
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
103
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
104
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
105
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
106
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
107
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
108
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
109
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
110
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
111
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
112
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
113
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
114
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
115
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
116
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
117
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
118
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
119
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
120
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
121
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
122
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
123
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
124
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
125
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
126
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
127
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
128
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
129
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
130
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
131
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
132
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
133
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
2
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
3
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
4
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
5
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
6
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
7
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
8
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
9
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
10
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
11
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
12
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
13
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
14
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
15
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
16
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
17
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
18
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
19
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
20
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
21
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
22
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
23
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
24
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
25
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
26
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
27
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
28
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
29
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
30
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
31
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
32
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
33
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
34
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
35
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
36
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
37
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
38
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
39
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
40
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
41
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
42
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
43
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
44
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
45
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
46
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
47
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
48
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
49
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
50
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
51
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
52
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
53
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
54
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
55
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
56
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
57
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
58
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
59
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
60
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
61
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
62
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
63
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
64
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
65
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
66
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
67
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
68
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
69
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
70
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
71
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
72
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
73
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
74
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
75
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
76
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
77
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
78
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
79
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
80
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
81
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
82
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
83
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
84
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
85
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
86
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
87
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
88
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
89
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
90
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
91
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
92
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
93
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
94
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
95
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
96
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
97
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
98
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
99
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
100
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
101
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
102
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
103
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
104
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
105
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
106
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
107
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
108
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
109
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
110
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
111
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
112
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
113
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
114
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
115
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
116
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
117
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
118
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
119
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
120
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
121
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
122
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
123
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
124
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
125
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
126
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
127
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
128
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
129
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
130
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
131
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
二、协议的编码和解码
对于自定义二进制协议,编码解码器往往是Netty开发的重点。这里直接给出相关类的代码。
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
2
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
3
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
4
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
5
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
6
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
7
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
8
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
9
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
10
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
11
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
12
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
13
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
14
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
15
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
16
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
17
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
18
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
19
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
20
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
21
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
22
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
23
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
24
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
25
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
26
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
27
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
28
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
29
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
30
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
31
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
32
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
33
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
34
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
35
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
36
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
37
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
38
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
39
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
40
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
41
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
42
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
43
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
44
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
45
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
46
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
47
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
48
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
49
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
50
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
51
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
52
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
53
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
54
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
55
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
56
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
57
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
58
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
59
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
60
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
61
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
2
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
3
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
4
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
5
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
6
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
7
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
8
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
9
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
10
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
11
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
12
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
13
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
14
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
15
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
16
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
17
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
18
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
19
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
20
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
21
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
22
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
23
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
24
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
25
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
26
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
27
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
28
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
29
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
30
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
31
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
32
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
33
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
34
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
35
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
36
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
37
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
38
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
39
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
40
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
41
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
42
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
43
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
44
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
45
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
46
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
47
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
48
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
49
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
50
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
51
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
52
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
53
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
54
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
2
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
3
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
4
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
5
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
6
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
7
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
8
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
9
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
10
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
11
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
12
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
13
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
14
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
15
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
16
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
17
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
18
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
19
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
20
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
21
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
22
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
23
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
24
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
25
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
26
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
27
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
28
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
29
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
30
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
31
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
32
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
33
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
34
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
35
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
36
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
37
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
38
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
39
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
40
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
41
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
42
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
43
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
44
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
45
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
46
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
47
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
48
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
49
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
50
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
51
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
52
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
53
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
54
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
55
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
56
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
57
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
58
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
59
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
60
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
61
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
62
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
63
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
64
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
65
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
66
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
67
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
68
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
69
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
70
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
71
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
72
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
73
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
74
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
75
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
76
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
77
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
78
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
79
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
80
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
81
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
82
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
83
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
84
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
85
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
86
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
87
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
88
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
89
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
90
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
91
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
92
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
93
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
94
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
95
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
96
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
97
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
98
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
99
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
100
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
101
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
102
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
103
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
104
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
105
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
106
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
107
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
108
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
109
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
110
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
三、服务器端实现
服务器端提供的功能是:
1、接收客户端的请求(非关闭命令),返回XLResponse类型的数据。
2、如果客户端的请求是关闭命令:shutdown,则服务器端关闭自身进程。
为了展示多协议的运用,这里客户端的请求采用的是基于问本行(\n\r)的协议。
具体代码如下:
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
2
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
3
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
4
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
5
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
6
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
7
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
8
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
9
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
10
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
11
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
12
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
13
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
14
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
15
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
16
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
17
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
18
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
19
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
20
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
21
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
22
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
23
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
24
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
25
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
26
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
27
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
28
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
29
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
30
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
31
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
32
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
33
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
34
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
35
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
36
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
37
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
38
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
39
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
40
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
41
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
42
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
43
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
44
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
45
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
46
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
47
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
48
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
49
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
50
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
51
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
52
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
53
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
54
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
55
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
56
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
57
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
58
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
59
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
60
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
61
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
62
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
63
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
64
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
65
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
66
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
67
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
68
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
69
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
70
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
71
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
72
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
73
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
74
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
75
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
76
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
77
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
78
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
79
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
80
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
81
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
82
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
83
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
84
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
85
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
2
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
3
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
4
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
5
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
6
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
7
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
8
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
9
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
10
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
11
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
12
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
13
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
14
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
15
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
16
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
17
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
18
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
19
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
20
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
21
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
22
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
23
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
24
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
25
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
26
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
27
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
28
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
29
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
30
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
31
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
32
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
33
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
34
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
35
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
36
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
37
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
38
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
39
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
40
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
41
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
42
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
43
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
44
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
45
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
46
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
47
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
48
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
49
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
50
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
51
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
52
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
53
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
54
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
55
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
56
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
57
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
58
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
59
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
60
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
61
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
62
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
63
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
64
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
65
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
66
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
67
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
68
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
69
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
70
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
71
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
72
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
73
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
74
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
75
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
76
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
77
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
78
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
79
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
80
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
81
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
82
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
83
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
84
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
85
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
86
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
87
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
88
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
89
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
90
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
91
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
92
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
93
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
94
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
95
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
96
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
97
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
98
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
99
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
100
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
四、客户端实现
客户端的功能是连接服务器,发送10次请求,然后发送关闭服务器的命令,最后主动关闭客户端。
关键代码如下:
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
2
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
3
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
4
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
5
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
6
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
7
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
8
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
9
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
10
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
11
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
12
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
13
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
14
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
15
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
16
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
17
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
18
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
19
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
20
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
21
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
22
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
23
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
24
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
25
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
26
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
27
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
28
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
29
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
30
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
31
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
32
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
33
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
34
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
35
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
36
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
37
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
38
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
39
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
40
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
41
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
42
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
43
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
44
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
45
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
46
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
47
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
48
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
49
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
50
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
51
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
52
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
53
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
54
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
55
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
56
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
57
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
58
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
59
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
60
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
61
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
62
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
63
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
64
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
65
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
66
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
67
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
68
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
69
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
70
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
71
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
72
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
73
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
74
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
75
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
76
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
77
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
78
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
79
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
80
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
81
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
82
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
83
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
84
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
85
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
86
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
87
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
88
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
89
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
90
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
91
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
2
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
3
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
4
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
5
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
6
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
7
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
8
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
9
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
10
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
11
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
12
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
13
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
14
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
15
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
16
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
17
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
18
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
2
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
3
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
4
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
5
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
6
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
7
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
8
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
9
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
10
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
11
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
12
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
13
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
14
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
15
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
16
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
17
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
18
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
19
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
20
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
21
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
22
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
23
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
24
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
25
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
26
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
27
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
28
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
29
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
30
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
31
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
32
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
33
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
34
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
35
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
36
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
37
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
38
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
39
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
40
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
41
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
42
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
43
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
44
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
45
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
46
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
47
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
48
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
49
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.blogjava.net/Images/dot.gif)
50
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
51
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
52
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
53
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
54
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
55
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
全文代码较多,写了很多注释,希望对读者有用,谢谢!
(友情提示:本博文章欢迎转载,但请注明出处:hankchen,http://www.blogjava.net/hankchen)
评论
int length = buffer.readInt(); // 数据包长
if (buffer.readableBytes() < length) {
buffer.resetReaderIndex();
return null;
}
一直都会进入这里?
INFO ( XLServer) server is started on port 8080
INFO (XLServerHandler) channelOpen
INFO (XLServerHandler) channelConnected
接受到信息writeRequested:XLResponse [encode=0, encrypt=0, extend=0, extend =0, sessionid=0, result=1, length=0, values={time=1374653003832, age=-182129588, name=hankchen}, ip=null]
ERROR(XLServerHandler) charsetName
java.lang.NullPointerException: charsetName
at com.factory.XLCharSetFactory.getCharset(XLCharSetFactory.java:25)
at com.util.ProtocolUtil.encode(ProtocolUtil.java:33)
at com.codec.XLServerEncoder.writeRequested(XLServerEncoder.java:46)
at org.jboss.netty.channel.Channels.write(Channels.java:611)
at org.jboss.netty.channel.Channels.write(Channels.java:578)
at org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:251)
at com.handle.XLServerHandler.sendResponse(XLServerHandler.java:104)
at com.handle.XLServerHandler.channelConnected(XLServerHandler.java:58)
at org.jboss.netty.handler.codec.oneone.OneToOneDecoder.handleUpstream(OneToOneDecoder.java:66)
at org.jboss.netty.channel.Channels.fireChannelConnected(Channels.java:233)
at org.jboss.netty.channel.socket.nio.NioAcceptedSocketChannel.<init>(NioAcceptedSocketChannel.java:53)
at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink$Boss.registerAcceptedChannel(NioServerSocketPipelineSink.java:285)
at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink$Boss.run(NioServerSocketPipelineSink.java:249)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
我给你补充一下这个类吧
package org.jboss.netty.example.xlsvr.factory;
import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException;
public class XLCharSetFactory {
static String[] charsetArray={"UTF-8","GBK","GB2312","ISO8859-1"};
/**
* :0:UTF-8,1:GBK,2:GB2312,3:ISO8859-1
* @param encode
* @return
* @throws InstantiationException
* @throws IllegalAccessException
* @throws ClassNotFoundException
*/
public static Charset getCharset(int encode) {
Charset charset=null;
if (encode == 0)
throw new NullPointerException("charsetName");
try {
switch(encode)
{
case 0:
charset = Charset.forName(charsetArray[0]);
break;
case 1:
charset = Charset.forName(charsetArray[1]);
break;
case 2:
charset = Charset.forName(charsetArray[2]);
break;
case 3:
charset = Charset.forName(charsetArray[3]);
break;
}
} catch (IllegalCharsetNameException e) {
e.printStackTrace();
} catch (UnsupportedCharsetException e) {
e.printStackTrace();
}
return charset;
}
}
相关推荐
在面对需要处理大量并发连接和高效数据传输的场景时,传统的通用协议和实现往往无法满足需求。例如,HTTP 服务器可能不适应大规模文件传输或实时消息传递的需求。这时,Netty 提供了一个解决方案,它允许开发者定制...
RTU模式是MODBUS协议的一种变体,它使用二进制格式传输数据,不包含每个字符的起始和结束标识,因此具有更高的传输效率。在RTU模式下,数据以连续的8位字节流形式发送,每两个字节之间用1.5个停止位隔开,以确保数据...
Netty的出现解决了通用协议库在大规模、高并发场景下的局限性,使得开发者能够快速构建针对特定需求的高度优化的协议实现。 Netty的核心特性在于它的异步事件驱动模型,这一模型基于Java的非阻塞I/O(NIO)API。...
在Dubbo中,传输层扮演着数据传输媒介的角色,确保请求和响应能够在分布式环境中准确无误地传递。在这个实现中,Dubbo选择了Netty作为基础网络库,因为Netty是一个高性能、异步事件驱动的网络应用框架,适用于快速...
- **JSON**:通用的数据交换格式,易于阅读和编写,但相对于二进制序列化协议,效率较低。 - **Hessian**:轻量级的二进制RPC协议,适合内部服务间通信。 - **Msgpack**:另一种高效的二进制序列化协议。 在选择...
Blister是一个用于操作苹果二进制PList文件格式的Java开源类库(可用于发送数据给iOS应用程序)。 重复文件检查工具 FindDup.tar FindDup 是一个简单易用的工具,用来检查计算机上重复的文件。 OpenID的Java客户端...
1. **网络通信**:Hadoop Common包含了一套基于Socket的网络通信组件,如Netty,用于节点间的高效数据传输。这些组件支持TCP/IP协议,确保了Hadoop集群内的节点能够快速、稳定地进行数据交互。 2. **I/O处理**:...
Dubbo默认使用Hessian作为序列化框架,这是一种二进制协议,具有轻量级、快速的特点。此外,还可以选择Duddo、FastJson和Java自带的序列化机制。Hessian通过HTTP POST方式传输数据,将辅助信息封装在HTTP头中,核心...
- **dubbo-common**:这是一个通用模块,包含了Dubbo框架共用的工具类,如IO处理、日志、配置、类处理等,以及线程池、二进制编码、JSON处理、数据存储接口等。这个模块为其他模块提供了基础支持。 - **dubbo-rpc-...
protobuf是Google的一种数据序列化协议,可以将结构化数据转化为二进制格式,便于网络传输。Java开发者可以通过protobuf编译器(protoc)将.proto文件转换为Java代码,其中包含了用于GRPC通信的Stub类。 2. **...
- **网络通信**: Hadoop Common提供了网络通信库,如Socket和Netty,用于节点间的通信,如数据传输、心跳检查和任务调度。 - **安全机制**: 支持Kerberos等认证和授权机制,以确保Hadoop集群的安全性。 - **日志...
Blister是一个用于操作苹果二进制PList文件格式的Java开源类库(可用于发送数据给iOS应用程序)。 重复文件检查工具 FindDup.tar FindDup 是一个简单易用的工具,用来检查计算机上重复的文件。 OpenID的Java客户端...
Blister是一个用于操作苹果二进制PList文件格式的Java开源类库(可用于发送数据给iOS应用程序)。 重复文件检查工具 FindDup.tar FindDup 是一个简单易用的工具,用来检查计算机上重复的文件。 OpenID的Java客户端...
Blister是一个用于操作苹果二进制PList文件格式的Java开源类库(可用于发送数据给iOS应用程序)。 重复文件检查工具 FindDup.tar FindDup 是一个简单易用的工具,用来检查计算机上重复的文件。 OpenID的Java客户端...
Blister是一个用于操作苹果二进制PList文件格式的Java开源类库(可用于发送数据给iOS应用程序)。 重复文件检查工具 FindDup.tar FindDup 是一个简单易用的工具,用来检查计算机上重复的文件。 OpenID的Java客户端...
Blister是一个用于操作苹果二进制PList文件格式的Java开源类库(可用于发送数据给iOS应用程序)。 重复文件检查工具 FindDup.tar FindDup 是一个简单易用的工具,用来检查计算机上重复的文件。 OpenID的Java客户端...