成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

netty實(shí)戰(zhàn)入門——安全保證-創(chuàng)新互聯(lián)

rpc 安全保證 空閑檢測(應(yīng)用層keep alive)

server端超過10s沒收到client信息,連接斷開
client超過5s沒有寫事件發(fā)生時(shí),則發(fā)送 keep alive,防止連接被斷開

成都創(chuàng)新互聯(lián)是一家網(wǎng)站設(shè)計(jì)公司,集創(chuàng)意、互聯(lián)網(wǎng)應(yīng)用、軟件技術(shù)為一體的創(chuàng)意網(wǎng)站建設(shè)服務(wù)商,主營產(chǎn)品:響應(yīng)式網(wǎng)站、品牌網(wǎng)站建設(shè)、營銷型網(wǎng)站。我們專注企業(yè)品牌在網(wǎng)站中的整體樹立,網(wǎng)絡(luò)互動的體驗(yàn),以及在手機(jī)等移動端的優(yōu)質(zhì)呈現(xiàn)。做網(wǎng)站、網(wǎng)站建設(shè)、移動互聯(lián)產(chǎn)品、網(wǎng)絡(luò)運(yùn)營、VI設(shè)計(jì)、云產(chǎn)品.運(yùn)維為核心業(yè)務(wù)。為用戶提供一站式解決方案,我們深知市場的競爭激烈,認(rèn)真對待每位客戶,為客戶提供賞析悅目的作品,網(wǎng)站的價(jià)值服務(wù)。

sever:

@Slf4j
public class ServerIdleCheckHandler extends IdleStateHandler {public ServerIdleCheckHandler() {super(10, 0, 0, TimeUnit.SECONDS);
    }

    @Override
    protected void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) throws Exception {if (IdleStateEvent.READER_IDLE_STATE_EVENT.equals(evt)) {log.info(" No reading for more than 10 seconds, connection closed");
            ctx.close();
        }
        super.channelIdle(ctx, evt);
    }
}

client:

觸發(fā)writeIdleEvent

public class ClientIdleCheckHandler extends IdleStateHandler {public ClientIdleCheckHandler() {super(0, 5, 0);
    }
}

處理writeIdleEvent,發(fā)送keepalive

@Sharable
@Slf4j
public class KeepaliveHandler extends ChannelInboundHandlerAdapter {@Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {if (IdleStateEvent.WRITER_IDLE_STATE_EVENT.equals(evt)) {log.info("write idle happen, so need to send keepalive");
            KeepaliveOperation keepaliveOperation = new KeepaliveOperation();
            RequestMessage requestMessage = new RequestMessage(IdUtil.nextId(), keepaliveOperation);
            ctx.writeAndFlush(requestMessage);
        }
        super.userEventTriggered(ctx, evt);
    }
}

添加到pipeLine

pipeline.addLast("idleChecker", new ClientIdleCheckHandler()); // 順序不能變
pipeline.addLast("keepaliveHandler", keepaliveHandler);        // 保證ClientIdleCheckHandler觸發(fā)的事件能被keepaliveHandler捕獲
黑白名單
IpSubnetFilterRule ipSubnetFilterRule = new IpSubnetFilterRule("127.0.0.1", 8, IpFilterRuleType.REJECT);
IpSubnetFilter ipSubnetFilter = new IpSubnetFilter(ipSubnetFilterRule);
自定義授權(quán)
@Slf4j
@Sharable
public class AuthHandler extends SimpleChannelInboundHandler{@Override
    protected void channelRead0(ChannelHandlerContext ctx, RequestMessage msg) throws Exception {Operation messageBody = msg.getMessageBody();
        try {if (messageBody instanceof AuthOperation) {AuthOperation authOperation = AuthOperation.class.cast(messageBody);
                AuthOperationResult result = authOperation.execute();
                if (result.isPassAuth()) {log.info("successfully pass auth");
                } else {log.error("fail to pass auth");
                    ctx.close();
                }
            }
        } finally {ctx.pipeline().remove(this);
        }
    }
}
SSL

生成證書

SelfSignedCertificate certificate = new SelfSignedCertificate();
SslContext sslContext = SslContextBuilder.forServer(certificate.certificate(), certificate.privateKey()).build();

添加sslHandler到pipline

SslHandler sslHandler = sslContext.newHandler(ch.alloc());
pipeline.addLast("sslHandler", sslHandler);

你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧

網(wǎng)頁標(biāo)題:netty實(shí)戰(zhàn)入門——安全保證-創(chuàng)新互聯(lián)
新聞來源:http://jinyejixie.com/article18/dpdpgp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、ChatGPT、網(wǎng)站排名用戶體驗(yàn)、商城網(wǎng)站、域名注冊

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)
拉孜县| 安远县| 云南省| 朝阳县| 屏南县| 白城市| 南涧| 万盛区| 疏附县| 揭东县| 响水县| 休宁县| 成武县| 特克斯县| 克东县| 镇原县| 巴彦县| 永昌县| 商丘市| 左云县| 雅安市| 留坝县| 南汇区| 章丘市| 贵阳市| 和硕县| 宜兰县| 昌江| 瑞安市| 蒙山县| 崇文区| 昌平区| 黑山县| 大港区| 财经| 黎城县| 赤城县| 关岭| 云林县| 翼城县| 涪陵区|