java nio写文件nul,异常java.nio.channels.ClosedChannelException当写入客户端通道时

I has created game server using netty 3.5.8.

At first time, there is not any problem with sending data from server to client.

But when server operation for a while, there are many exception [java.nio.channels.ClosedChannelException] occurred when i write data to client channel.

Any one has get this exception before. Is there any tip to fix this?

I think about cache buffer cause this.

My code sample like this:

ChannelBuffer bff = ChannelBuffers.buffer(18);

bff.writeByte(Events.S_SERVER_PUSH);

bff.writeByte((byte)0);

bff.writeInt(idRoom);

bff.writeInt(playerCnt);

bff.writeInt(gameCnt);

bff.writeInt(freePlayer);

channel.write(bff);

Exception: java.nio.channels.ClosedChannelException

java.nio.channels.ClosedChannelException

at org.jboss.netty.channel.socket.nio.AbstractNioWorker.cleanUpWriteBuffer(AbstractNioWorker.java:784)

at org.jboss.netty.channel.socket.nio.AbstractNioWorker.writeFromUserCode(AbstractNioWorker.java:507)

at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.handleAcceptedSocket(NioServerSocketPipelineSink.java:129)

at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.eventSunk(NioServerSocketPipelineSink.java:66)

at org.jboss.netty.channel.Channels.write(Channels.java:733)

at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.doEncode(OneToOneEncoder.java:71)

at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:60)

at org.jboss.netty.channel.Channels.write(Channels.java:712)

at org.jboss.netty.channel.Channels.write(Channels.java:679)

at org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:248)

at myclass.SendPushData(GameRoom.java:231)

at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)

at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:458)

at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:439)

at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303)

at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)

at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)

at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:84)

at org.jboss.netty.channel.socket.nio.AbstractNioWorker.processSelectedKeys(AbstractNioWorker.java:471)

at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:332)

at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:35)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

解决方案

ClosedChannelException merely tells you that the connection has been closed so the write request you issued could not be done. It usually means either 1) your application closed the connection somewhere else before you write the message or 2) your peer closed the connection before reading your message. If you fix (1) and (2), you should not see the ClosedChannelException anymore.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值