[netty] On the netty server side, the main sending command is sent. If the other party's client does not receive it, how to set it to resend? ?

public class MessageHandler extends ChannelInboundHandlerAdapter implements ChannelOutboundHandler {

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        Map newMap = new HashMap<>();
        // Resend the message every three seconds
        ctx.executor().scheduleAtFixedRate(() -> {
            if (map.size() > 0) 
            {
                map.forEach((k, v) -> {
                    ctx.writeAndFlush(v.data);
                    v.times = v.times + 1;
                    if (v.times < 3) 
                    {
                        // Keep unsent three times.
                        newMap.put(v.id, v);
                    }
                });
            }
            map = newMap;
        }, 3, 3, TimeUnit.SECONDS);
    }
}

Guess you like

Origin www.cnblogs.com/wxxujian/p/12706420.html