V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
nextdiscover
V2EX  ›  Java

netty 里面的 channel 什么时候会触发关闭?

  •  
  •   nextdiscover · Sep 19, 2018 · 10925 views
    This topic created in 2777 days ago, the information mentioned may be changed or developed.

    netty 里面的 channel 什么时候会触发关闭?我的本地连接经常断开,使用 channel.isActive()返回 false,不知道哪里触发了断开。有没有大佬知道,求指导

    11 replies    2018-09-20 14:16:12 +08:00
    LucasLee92
        1
    LucasLee92  
       Sep 19, 2018
    兄弟,有空去注册一个 stackoverflow 的账号吧,至少注册的时候会教你一些问别人之前的一些常识
    nextdiscover
        2
    nextdiscover  
    OP
       Sep 19, 2018
    @LucasLee92 在上面或者百度或者 google 能找到答案我还来这里问,你怎么知道我没查就来问,没事不要揣测别人,你不想回答就别回复
    guyeu
        3
    guyeu  
       Sep 19, 2018
    最近刚好在看这部份内容,有很多种情况,isActive()返回 false 也不一定是连接断开,channel 有四种状态,registered、active、inactive、unregistered,你可以用 handler 拦截这些事件来判断连接是在什么时候断开的。
    anthow
        4
    anthow  
       Sep 20, 2018
    如果是服务端的话可能对方不是长连接,请求一次就 gg,这样你这边 channel.isActive()就会返回 false
    nextdiscover
        5
    nextdiscover  
    OP
       Sep 20, 2018 via iPhone
    @guyeu 了解了,谢谢指导,我去试一下
    nextdiscover
        6
    nextdiscover  
    OP
       Sep 20, 2018 via iPhone
    @anthow 嗯嗯,服务端是 php 写的长连接,因为我是移动端开发,所以 netty 了解的比较少,小白一枚,还望多多指教,谢谢
    nextdiscover
        7
    nextdiscover  
    OP
       Sep 20, 2018 via iPhone
    @guyeu 我用 handle 拦截了,调用 channelIncative 方法应该就是断开了,我重新连接的时候,连接成功后接着发了一个心跳的字符串,然后接着就回调 channelInactive 了,不知道为什么
    sagaxu
        8
    sagaxu  
       Sep 20, 2018 via Android
    tcp 协议了解一下
    goinghugh
        9
    goinghugh  
       Sep 20, 2018
    调试的时候可以使用 telnet 命令看看服务端是否正常,先缩小问题的范围
    guyeu
        10
    guyeu  
       Sep 20, 2018
    emmmm 楼上说的对 先确定是否是服务端的问题,如果是,可以先排查一下参数设置的是否有问题,再看看 handler 里的逻辑是不是有问题
    nextdiscover
        11
    nextdiscover  
    OP
       Sep 20, 2018
    @guyeu 嗯嗯,谢谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1004 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 19:09 · PVG 03:09 · LAX 12:09 · JFK 15:09
    ♥ Do have faith in what you're doing.