NettyWebRTC

netty双向心跳的设计

2015-10-19  本文已影响433人  虫二无边
Paste_Image.png
/**
 * heart beat command
 * Created by lif on 2015/10/10.
 */
public class HeartBeatHandler extends ChannelInboundHandlerAdapter implements MsgHandler  {

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        if (evt instanceof IdleStateEvent) {
            IdleStateEvent event = (IdleStateEvent) evt;
            if (event.state() == IdleState.READER_IDLE) {
                // Read timeout
                System.out.println("READER_IDLE: read timeout from " + ctx.channel().remoteAddress());

                String userId = CommonUtil.getLoginInfo(ctx.channel()).getUser_id();
                ConnectionManager.removeConn(userId);

                // close connection
                if (ctx.channel().isOpen()) {
                    ctx.channel().close();
                }

            }
        }
    }
上一篇 下一篇

猜你喜欢

热点阅读