@@ -0,0 +1,2140 @@
+package com.server;%0A%0Aimport io.netty.channel.Channel;%0Aimport io.netty.channel.ChannelHandlerContext;%0Aimport io.netty.channel.SimpleChannelInboundHandler;%0Aimport io.netty.channel.group.ChannelGroup;%0Aimport io.netty.channel.group.DefaultChannelGroup;%0Aimport io.netty.util.concurrent.GlobalEventExecutor;%0A%0A/**%0A * Created by form on 2017-07-20.%0A */%0Apublic class ServerChatHandler extends SimpleChannelInboundHandler%3CString%3E %7B%0A%0A    public static final ChannelGroup group = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);%0A%0A    @Override%0A    protected void channelRead0(ChannelHandlerContext arg0, String arg1) throws Exception%7B%0A        Channel channel = arg0.channel();%0A        for(Channel ch : group)%7B%0A            if(ch == channel)%7B%0A                ch.writeAndFlush(%22%5Byou%5D%EF%BC%9A%22+arg1+%22%5Cn%22);%0A            %7Delse%7B%0A                ch.writeAndFlush(%22%5B%22+channel.remoteAddress()+%22%5D: %22+arg1+%22%5Cn%22);%0A            %7D%0A        %7D%0A%0A    %7D%0A%0A    @Override%0A    public void handlerAdded(ChannelHandlerContext ctx) throws Exception%7B%0A        Channel channel = ctx.channel();%0A        for(Channel ch : group)%7B%0A            ch.writeAndFlush(%22%5B%22+channel.remoteAddress()+%22%5D %22+%22is coming!%5Cn%22);%0A        %7D%0A        group.add(channel);%0A    %7D%0A%0A    @Override%0A    public void handlerRemoved(ChannelHandlerContext ctx) throws Exception%7B%0A        Channel channel = ctx.channel();%0A        for(Channel ch : group)%7B%0A            ch.writeAndFlush(%22%5B%22+channel.remoteAddress()+%22%5D %22+%22is going!%5Cn%22);%0A        %7D%0A        group.remove(channel);%0A    %7D%0A%0A    @Override%0A    public void channelActive(ChannelHandlerContext ctx) throws Exception%7B%0A        Channel channel = ctx.channel();%0A        System.out.println(%22%5B%22+channel.remoteAddress()+%22%5D %22+%22online%22);%0A    %7D%0A%0A    @Override%0A    public void channelInactive(ChannelHandlerContext ctx) throws Exception%7B%0A        Channel channel = ctx.channel();%0A        System.out.println(%22%5B%22+channel.remoteAddress()+%22%5D %22+%22offline%22);%0A    %7D%0A%0A    @Override%0A    public void exceptionCaught(ChannelHandlerContext ctx,Throwable cause) throws Exception%7B%0A        System.out.println(%22%5B%22+ctx.channel().remoteAddress()+%22%5D%22+%22exit the room%22);%0A        ctx.close().sync();%0A    %7D%0A%7D%0A

Create ServerChatHandler.java