| | |
| | | package com.sinata.push.util.echo; |
| | | |
| | | import com.sinata.push.util.SpringUtil; |
| | | import io.netty.buffer.Unpooled; |
| | | import io.netty.channel.ChannelHandlerContext; |
| | | import io.netty.channel.ChannelPromise; |
| | |
| | | import io.netty.handler.timeout.IdleState; |
| | | import io.netty.handler.timeout.IdleStateEvent; |
| | | import io.netty.util.ReferenceCountUtil; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | |
| | | import java.net.InetSocketAddress; |
| | | import java.util.HashMap; |
| | | |
| | | public class DiscardServerHandler extends SimpleChannelInboundHandler<String> { |
| | | |
| | | private NettyServerController nettyServerController = SpringUtil.getObject(NettyServerController.class); |
| | | private NettyServerController nettyServerController = new NettyServerController(); |
| | | |
| | | public static boolean isdebug = true; |
| | | |
| | |
| | | public void channelRead(ChannelHandlerContext ctx, Object msg) { |
| | | InetSocketAddress insocket = (InetSocketAddress) ctx.channel().remoteAddress(); |
| | | if(isdebug) { |
| | | System.err.println(insocket.getAddress() + ": 收到客户端数据......."); |
| | | // System.err.println(insocket.getAddress() + ": 收到客户端数据......."); |
| | | } |
| | | try { |
| | | // 调用service |
| | |
| | | protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { |
| | | InetSocketAddress insocket = (InetSocketAddress) ctx.channel().remoteAddress(); |
| | | if(isdebug) { |
| | | System.err.println(insocket.getAddress() + ": 收到客户端数据......."); |
| | | // System.err.println(insocket.getAddress() + ": 收到客户端数据......."); |
| | | } |
| | | try { |
| | | // 调用service |
| | |
| | | public void channelActive(final ChannelHandlerContext ctx) throws Exception { |
| | | InetSocketAddress insocket = (InetSocketAddress) ctx.channel().remoteAddress(); |
| | | if(isdebug) { |
| | | System.err.println(insocket.getAddress() + ": Connect successful......"); |
| | | // System.err.println(insocket.getAddress() + ": Connect successful......"); |
| | | } |
| | | } |
| | | |
| | |
| | | // System.err.println(insocket.getAddress() + ": Disconnect connection......"); |
| | | } |
| | | NettyChannelMap.remove(ctx); |
| | | System.err.println("清除通道" + ctx); |
| | | // System.err.println("清除通道" + ctx); |
| | | // super.channelInactive(ctx); |
| | | } |
| | | |