Netty java.io.IOException: Connection reset by peer 大神们咋处理的?

xiaosima2017 2016-11-22 11:05:43
java.io.IOException: Connection reset by peer
at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
at sun.nio.ch.IOUtil.read(IOUtil.java:192)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380)
at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288)
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1098)
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:112)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:544)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:485)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:399)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:371)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:742)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:145)
at java.lang.Thread.run(Thread.java:745)
服务端发送了数据,显示发送成功!但是客户端没有收到。并且出现了异常!
...全文
7717 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_24557927 2019-01-21
  • 打赏
  • 举报
回复
请求最后怎么屏蔽掉这个异常的啊
nikyotensai 2016-11-22
  • 打赏
  • 举报
回复
引用 1 楼 qq_26508409 的回复:
连接被重置了。。。
http://blog.sina.com.cn/s/blog_43eb83b90102dseg.html
hai046 2016-11-22
  • 打赏
  • 举报
回复
Channel channel = channelHandlerContext.channel(); if (channel.isActive()) {//在这判断判断 }
xiaosima2017 2016-11-22
  • 打赏
  • 举报
回复
有解决方案吗?
nikyotensai 2016-11-22
  • 打赏
  • 举报
回复
连接被重置了。。。
hai046 2016-11-22
  • 打赏
  • 举报
回复
我在
io.netty.channel.ChannelHandlerAdapter#handlerRemoved#handlerRemoved 
io.netty.channel.ChannelHandlerAdapter#handlerRemoved#exceptionCaught 
io.netty.channel.ChannelHandlerAdapter#handlerRemoved#userEventTriggered   


    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        super.userEventTriggered(ctx, evt);
        if (evt instanceof IdleStateEvent) {
            IdleStateEvent event = (IdleStateEvent) evt;

            if (event.state().equals(IdleState.READER_IDLE)) {
                ctx.close();
              //标志该链接已经close 了 
            }
}

  
在这三个地方标记 该链接已经close 了 在发送的时候检查如果该用户已经offline了 就不用发送了[麻烦把6楼删掉]
hai046 2016-11-22
  • 打赏
  • 举报
回复
我在
com.jiemoapp.push.server.handler.AuthHandlerAdapter#handlerRemoved 
com.jiemoapp.push.server.handler.AuthHandlerAdapter#exceptionCaught 
com.jiemoapp.push.server.handler.AuthHandlerAdapter#userEventTriggered   


    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        super.userEventTriggered(ctx, evt);
        if (evt instanceof IdleStateEvent) {
            IdleStateEvent event = (IdleStateEvent) evt;

            if (event.state().equals(IdleState.READER_IDLE)) {
                ctx.close();
              //标志该链接已经close 了 
            }
}

  
在这三个地方标记 该链接已经close 了 在发送的时候检查如果该用户已经offline了 就不用发送了
xiaosima2017 2016-11-22
  • 打赏
  • 举报
回复





引用 3 楼 hai046 的回复:
Channel channel = channelHandlerContext.channel();
if (channel.isActive()) {//在这判断判断



}
你说的那个做的判断!这是加上以上 但是还是走下面的代码,此外 我看到了 这个是写一个handler 把吗?是跟它一样加到此处吗?

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧