Handle reception of partial data in WS client.

This commit is contained in:
Marc Baloup 2023-04-10 19:15:58 +02:00
parent 5b43aed0b4
commit 4259e5eccd

View File

@ -43,13 +43,20 @@ public abstract class AbstractClientWS implements AbstractWS {
Listener.super.onOpen(webSocket);
}
StringBuilder partialData = new StringBuilder();
@Override
public CompletionStage<?> onText(WebSocket webSocket, CharSequence data, boolean last) {
partialData.append(data.toString());
if (last) {
try {
AbstractClientWS.this.handleReceivedMessage(data.toString());
AbstractClientWS.this.handleReceivedMessage(partialData.toString());
} catch (Exception e) {
logError("Error handling reception of text.", e);
}
partialData = new StringBuilder();
}
return Listener.super.onText(webSocket, data, last);
}