引用来自“Black_JackQ”的评论异步的,client需多次
read处理完数据。
是这样做的,但是目前观察消息接受率只有70%左右,代码如下:
socket.read(byteBuffer, null, new CompletionHandler() {
@Override
public void completed(Integer result, Void attachment) {
if(result==-1){
LOG.debug("server socket closed, close client {}.", clientIdentifier);
close(true);
return;
}
byteBuffer.clear();
LOG.debug("get data from server :"+getByteBufferContentString(byteBuffer));
byteBuffer.clear();
if (result > 0) {
if (!connected) {
handleConnect();
} else {
doProcess();
}
}
socket.read(byteBuffer, null, this);
}
@Override
public void failed(Throwable exc, Void attachment) {
LOG.error("Client read failed,{}.", exc.toString());
}
});