Java Netty:在出现异常时关闭客户端的连接

Java Netty:在出现异常时关闭客户端的连接,java,netty,Java,Netty,因此,我有一个UDP服务器,当我遇到异常时,我想关闭与客户端的连接。因此,在我的处理程序中,我有以下内容: @Override public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { logger.error("Error received while processing message.", e.getCause()); e.getChannel()

因此,我有一个UDP服务器,当我遇到异常时,我想关闭与客户端的连接。因此,在我的处理程序中,我有以下内容:

@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    logger.error("Error received while processing message.", e.getCause());
    e.getChannel().close(); // this is bad mojo
}

但是,这将关闭服务器套接字,服务器停止接受新连接。但是e.getChannel.getRemoteAddress在该方法中返回null。那么,如何在不关闭整个服务器的情况下关闭与客户机的连接呢?

没有UDP服务器套接字,您说的是数据报套接字,对吗?。UDP是一种无连接协议,因此没有要关闭的客户端连接。