Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Netty服务器和客户端超时_Java_Netty - Fatal编程技术网

Java Netty服务器和客户端超时

Java Netty服务器和客户端超时,java,netty,Java,Netty,我想在服务器关闭时强制超时异常(对于断开的网络) 我尝试以下配置: pipeline.addLast("readTimeoutHandler", new ReadTimeoutHandler(5)); pipeline.addLast("writeTimeoutHandler", new WriteTimeoutHandler(5)); // Add the text line codec combination first, pipeline.addLast("framer", new Del

我想在服务器关闭时强制超时异常(对于断开的网络)

我尝试以下配置:

pipeline.addLast("readTimeoutHandler", new ReadTimeoutHandler(5));
pipeline.addLast("writeTimeoutHandler", new WriteTimeoutHandler(5));
// Add the text line codec combination first,
pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));

// Add the encoder and decoder are static as these are sharable
pipeline.addLast("decoder", new StringDecoder());
pipeline.addLast("encoder", new StringEncoder());

// Enable stream compression
pipeline.addLast("deflater", new JZlibEncoder(ZlibWrapper.GZIP));
pipeline.addLast("inflater", new JZlibDecoder(ZlibWrapper.GZIP));

pipeline.addLast(clientHandler);
但是当我关闭TCP服务器时,客户端可以尝试使用
channel.writeAndFlush(tempMsg+AbstractSocketInitializer.ESCAPE_CHAR)发送消息

客户端从不抛出异常


当尝试在通道中写入而从未收到响应时,如何强制客户端引发异常?

您可以查找
通道不活动事件并对其采取行动,即引发异常或其他事件。在客户端的一个
ChannelInboundHandler
s中,重写以下方法:

  @Override
public void channelInactive(final ChannelHandlerContext ctx) throws Exception {
  // do something here
}
该方法将在您关闭服务器后立即触发