9
9
10
10
mvn -PChatServer -Dport=1111 clean package exec:exec
11
11
12
- 下面是控制台的输出
12
+ 下面是控制台的主要输出(删除了部分行)
13
13
14
14
Listing 11.5 Compile and start the ChatServer
15
15
@@ -26,17 +26,17 @@ Listing 11.5 Compile and start the ChatServer
26
26
[ INFO] --- exec-maven-plugin:1.2.1: exec (default-cli) @ chat-server ---
27
27
Starting ChatServer on port 9999
28
28
29
- 可以在浏览器中通过 http://localhost:9999 地址访问程序:
29
+ 可以在浏览器中通过 http://localhost:9999 地址访问程序。图11.5展示了此程序在Chrome浏览器下的用户界面。
30
30
31
31
Figure 11.5 WebSockets ChatServer demonstration
32
32
33
33
![ ] (../images/Figure 11.5 WebSockets ChatServer demonstration.jpg)
34
34
35
- 图中显示了两个客户端可以交互了 。
36
-
35
+ 图中显示了两个已经连接了的客户端。第一个客户端是通过上面的图形界面连接的,第二个是通过Chrome浏览器底部的命令行连接的 。
36
+ 你可以注意到,这两个客户端都在发送消息,每条消息都会显示在两个客户端上。
37
37
###如何加密?
38
38
39
- 通过添加 SslHandler 到 ChannelPipeline 来配置加密 。如下:
39
+ 在实际场景中,加密是必不可少的。在Netty中实现加密并不麻烦,你只需要向 ChannelPipeline 中添加 SslHandler ,然后配置一下即可 。如下:
40
40
41
41
Listing 11.6 Add encryption to the ChannelPipeline
42
42
@@ -59,7 +59,7 @@ Listing 11.6 Add encryption to the ChannelPipeline
59
59
60
60
1.扩展 ChatServerInitializer 来实现加密
61
61
62
- 2.SslHandler 到 ChannelPipeline
62
+ 2.向 ChannelPipeline 中添加SslHandler
63
63
64
64
最后修改 ChatServer,使用 SecureChatServerInitializer 并传入 SSLContext
65
65
@@ -101,9 +101,9 @@ Listing 11.7 Add encryption to the ChatServer
101
101
102
102
1.扩展 ChatServer
103
103
104
- 2.返回先前创建的 SecureChatServerInitializer 来启动加密
104
+ 2.返回先前创建的 SecureChatServerInitializer 来启用加密
105
105
106
- 这样,就在所有的通信中使用了 [ SSL/TLS] ( http://tools.ietf.org/html/rfc5246 ) 加密。下面是启动程序:
106
+ 这样,就在所有的通信中使用了 [ SSL/TLS] ( http://tools.ietf.org/html/rfc5246 ) 加密。和前面一样,你可以使用Maven拉取应用需要的所有依赖,并启动它,如下所示。
107
107
108
108
Listing 11.8 Start the SecureChatServer
109
109
@@ -121,5 +121,5 @@ Listing 11.8 Start the SecureChatServer
121
121
[ INFO] --- exec-maven-plugin:1.2.1: exec (default-cli) @ chat-server ---
122
122
Starting SecureChatServer on port 9999
123
123
124
- 可以通过 HTTPS 地址: https://localhost:9999 来访问SecureChatServer
124
+ 现在你可以通过 HTTPS 地址: https://localhost:9999 来访问SecureChatServer 了。
125
125
0 commit comments