netty套接字读取超时不会关闭套接字

时间:2014-10-30 09:31:26

标签: sockets timeout netty

我有一个使用netty的应用程序:tcp监听端口。当连接到来时,它首先读取请求并写入响应。在读取部分中,我实现了REadTimeout处理程序,如果发生读取超时,则会抛出异常。问题是,在readtimeout异常中,我无法关闭与客户端的套接字连接,并且它永远等待套接字。如何在发生超时时终止/关闭客户端之间的套接字连接。

在exceptionCought方法中我试图关闭连接,但正如我告诉socket仍然存在。我可以为客户检查这个。

@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
        throws Exception {
    super.exceptionCaught(ctx, e);
    Channel channel = e.getChannel();
    channel.close();
    //I tried below lines but does not close the socket. 
    //channel.disconnect();
    //NettyHelper.close(channel);
    //org.jboss.netty.channel.Channels.close(channel);
}

0 个答案:

没有答案
相关问题