1

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:

  • the 'current_bytes' are the whole binary message sent from the client, rest of the payload array is not related to this session call
  • the 'current_bytes' are partial binary message and I should collect the data till offset + len will be equal to payload.length
  • the 'current_bytes' are partial binary message, but I should manage the notion of the 'full message delivered' myself by the means of inspecting the payload content

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?

GullerYA
  • 1,320
  • 14
  • 27

1 Answers1

2

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)
Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
  • Could you please take a look at the following question? https://stackoverflow.com/questions/12672684/starting-up-embedded-jetty-server-for-a-jar-file It doesnt have relevant answer, and while thats not my question I am facing the same problem. Also it might be relevant for those who trying to serve static content from within a runnable jar thats running an embedded Jetty... – Oliver Apr 16 '19 at 18:32
  • 1
    @Z3d4s don't hijack other questions / answers pointing to unrelated questions. that doesn't help anyone. feel free to ask a new question, or better yet search stackoverflow for the answer to your question [(it's been answered about a dozen times in different ways by myself)](https://stackoverflow.com/questions/49610329/using-web-xml-with-webappcontext-in-jetty) – Joakim Erdfelt Apr 16 '19 at 20:35