Skip to content

Commit

Permalink
better ws support for large messages
Browse files Browse the repository at this point in the history
  • Loading branch information
zb-sr committed Oct 18, 2024
1 parent e74cd4f commit 3702211
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
import com.sportradar.mbs.sdk.internal.connection.msg.base.WsInputMessage;
import com.sportradar.mbs.sdk.internal.connection.msg.base.WsOutputMessage;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.framing.Framedata;
import org.java_websocket.framing.TextFrame;
import org.java_websocket.enums.Opcode;
import org.java_websocket.handshake.ServerHandshake;

import java.net.URI;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -102,14 +100,9 @@ private void sendLoop() {
}

private void sendMsg(final WebSocket ws, final List<ByteBuffer> msgs) {
final List<Framedata> frames = new ArrayList<>();
for (int i = 0; i < msgs.size(); i++) {
final TextFrame frame = new TextFrame();
frame.setPayload(msgs.get(i));
frame.setFin(i == msgs.size() - 1);
frames.add(frame);
ws.sendFragmentedFrame(Opcode.TEXT, msgs.get(i), i == (msgs.size() - 1));
}
ws.sendFrame(frames);
}

private void reconnectWebSocket(final WebSocket ws, final boolean throwExc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private List<ByteBuffer> createFrames(final Request request) throws JsonProcessi
int offset = 0;
while (offset < bytes.length) {
final int chunkSize = Math.min(bytes.length - offset, MAX_CHUNK_SIZE);
final ByteBuffer buffer = ByteBuffer.wrap(bytes, offset, offset + chunkSize);
final ByteBuffer buffer = ByteBuffer.wrap(bytes, offset, chunkSize);
result.add(buffer);
offset += chunkSize;
}
Expand Down

0 comments on commit 3702211

Please sign in to comment.