调用心跳连接经常失效
15:30:55.791 [Quick Timer] INFO org.smartboot.socket.extension.plugins.HeartPlugin - session:org.smartboot.socket.transport.TcpAioSession@4e1f25a7 已失效,移除心跳任务
源代码
1 WriteBuffer writeBuffer = start.writeBuffer(); 2 if (i % 5 == 0) { 3 byte[] content = "heart message".getBytes(); 4 writeBuffer.writeInt(content.length); 5 writeBuffer.write(content); 6 } else { 7 byte[] content = "heart".getBytes(); 8 writeBuffer.writeInt(content.length); 9 writeBuffer.write(content); 10 } 11 Thread.sleep(1000L);
错误原因:输出流没有刷新导致,增加writeBuffer.flush()
1 WriteBuffer writeBuffer = start.writeBuffer(); 2 if (i % 5 == 0) { 3 byte[] content = "heart message".getBytes(); 4 writeBuffer.writeInt(content.length); 5 writeBuffer.write(content); 6 } else { 7 byte[] content = "heart".getBytes(); 8 writeBuffer.writeInt(content.length); 9 writeBuffer.write(content); 10 } 11 writeBuffer.flush() 12 Thread.sleep(1000L);
标签:heart,socket,content,write,writeInt,失效,byte,writeBuffer,smart From: https://www.cnblogs.com/mapeiran/p/17582751.html