SecureChatServerHandler Class — netty Architecture
Architecture documentation for the SecureChatServerHandler class in SecureChatServerHandler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD ad2c2edf_e4a1_2675_364b_725729ad332a["SecureChatServerHandler"] db411dc1_9050_f379_92f7_4f7bb3b0ff43["SecureChatServerHandler.java"] ad2c2edf_e4a1_2675_364b_725729ad332a -->|defined in| db411dc1_9050_f379_92f7_4f7bb3b0ff43 2341e78f_e3e6_dbad_cd5c_0a88087b07da["channelActive()"] ad2c2edf_e4a1_2675_364b_725729ad332a -->|method| 2341e78f_e3e6_dbad_cd5c_0a88087b07da 77167c82_4a98_5027_d91f_914fdf82f922["channelRead0()"] ad2c2edf_e4a1_2675_364b_725729ad332a -->|method| 77167c82_4a98_5027_d91f_914fdf82f922 500b114d_554b_eea1_c472_eca6309a1697["exceptionCaught()"] ad2c2edf_e4a1_2675_364b_725729ad332a -->|method| 500b114d_554b_eea1_c472_eca6309a1697
Relationship Graph
Source Code
example/src/main/java/io/netty/example/securechat/SecureChatServerHandler.java lines 31–73
public class SecureChatServerHandler extends SimpleChannelInboundHandler<String> {
static final ChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
@Override
public void channelActive(final ChannelHandlerContext ctx) {
// Once session is secured, send a greeting and register the channel to the global channel
// list so the channel received the messages from others.
ctx.pipeline().get(SslHandler.class).handshakeFuture().addListener(future -> {
ctx.writeAndFlush(
"Welcome to secure chat service!\n");
ctx.writeAndFlush(
"Your session is protected by " +
ctx.pipeline().get(SslHandler.class).engine().getSession().getCipherSuite() +
" cipher suite.\n");
channels.add(ctx.channel());
});
}
@Override
public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
// Send the received message to all channels but the current one.
for (Channel c: channels) {
if (c != ctx.channel()) {
c.writeAndFlush("[" + ctx.channel().remoteAddress() + "] " + msg + '\n');
} else {
c.writeAndFlush("[you] " + msg + '\n');
}
}
// Close the connection if the client has sent 'bye'.
if ("bye".equals(msg.toLowerCase())) {
ctx.close();
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace();
ctx.close();
}
}
Source
Frequently Asked Questions
What is the SecureChatServerHandler class?
SecureChatServerHandler is a class in the netty codebase, defined in example/src/main/java/io/netty/example/securechat/SecureChatServerHandler.java.
Where is SecureChatServerHandler defined?
SecureChatServerHandler is defined in example/src/main/java/io/netty/example/securechat/SecureChatServerHandler.java at line 31.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free