我的应用中,客户端与服务器是长连接,客户端断开后,需要清空一些玩家的缓存信息。
我测试了客户端强制关闭后,服务器会打印一下异常信息:
java.io.IOException: 远程主机强迫关闭了一个现有的连接。
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:225)
at sun.nio.ch.IOUtil.read(IOUtil.java:193)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:359)
at io.netty.buffer.UnpooledUnsafeDirectByteBuf.setBytes(UnpooledUnsafeDirectByteBuf.java:436)
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:870)
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:208)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:88)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:485)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:452)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:346)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
at java.lang.Thread.run(Thread.java:722)
但是在我的应用层感觉没法捕获到,也不好判断。如果不检测这个异常,有什么好的解决方案来监听客户端异常断开
...全文
81734打赏收藏
关于 netty 检测客户端异常关闭 有什么好的 解决方案
我的应用中,客户端与服务器是长连接,客户端断开后,需要清空一些玩家的缓存信息。 我测试了客户端强制关闭后,服务器会打印一下异常信息: java.io.IOException: 远程主机强迫关闭了一个现有的连接。引用 at sun.nio.ch.SocketDispatcher.read0(Native Method) at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43) at sun.nio.ch.IOUtil.readInt