Reputation: 1776
API signature of the obWebSocketBinary
method of WebSocketListener
and it's subclasses looks like this:
void onWebSocketBinary(byte[] payload, int offset, int len)
Let's call the bytes in the payload
from offset
due len
- 'current_bytes'. How should I interpret this API:
payload
array is not related to this session calloffset
+ len
will be equal to payload.length
If, presumably, the offset
due len
is not the full content of the payload
array, can I consider it as a 'shared' memory used as a buffer for different payloads?
Upvotes: 1
Views: 245
Reputation: 49545
The API is whole binary messages.
The reason for the offset/len is because the byte buffers are allocated before the entire overall length of the entire websocket message is known.
So the byte buffer sent to you is often larger then the message.
If you want partial messages, then you'll need to know the "fin" (final) flag.
For partial binary, you'd use the WebSocketPartialListener
interface and use the method ...
onWebSocketPartialBinary(java.nio.ByteBuffer payload, boolean fin)
Upvotes: 2