| | |
| | | import com.xcong.excoin.netty.common.Contans; |
| | | import com.xcong.excoin.netty.common.NettyTools; |
| | | import com.xcong.excoin.netty.dispatch.MsgDispatch; |
| | | import com.xcong.excoin.utils.SpringContextHolder; |
| | | import io.netty.buffer.ByteBuf; |
| | | import io.netty.buffer.Unpooled; |
| | | import io.netty.channel.*; |
| | |
| | | import static io.netty.handler.codec.http.HttpUtil.isKeepAlive; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @email wangdoubleone@gmail.com |
| | | * @date 2019-05-06 |
| | | * 项目启动时,在控制台有 |
| | | * Unable to proxy interface-implementing method [public final void io.netty.channel.ChannelInitializer.channelRegistered(io.netty.channel.ChannelHandlerContext) throws java.lang.Exception] because it is marked as final: Consider using interface-based JDK proxies instead! |
| | | * 输出 |
| | | * 表明,此类将走代理enhancerbyspringcglib代理 |
| | | * 此时,获取到此类将为null(不知道原因),从而导致netty连接在初始化时会有空指针异常 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | |
| | | |
| | | private WebSocketServerHandshaker handshaker; |
| | | |
| | | @Resource(name = "msgDispatch") |
| | | private MsgDispatch msgDispatch; |
| | | // @Resource(name = "msgDispatch") |
| | | // private MsgDispatch msgDispatch; |
| | | |
| | | @Override |
| | | public void channelActive(ChannelHandlerContext ctx) throws Exception { |
| | |
| | | if (content.contains(Contans.HEART_BEAT)) { |
| | | resetTimes(ctx.channel()); |
| | | } else { |
| | | this.msgDispatch.webSocketDispatch(ctx, content); |
| | | SpringContextHolder.getBean(MsgDispatch.class).webSocketDispatch(ctx, content); |
| | | } |
| | | } catch (ClassCastException e) { |
| | | content = ((CloseWebSocketFrame) frame).reasonText(); |