TooTallNate / Java-WebSocket

A barebones WebSocket client and server implementation written in 100% Java.
http://tootallnate.github.io/Java-WebSocket
MIT License
10.36k stars 2.57k forks source link

using fragmentation problem #1356

Closed JanuNoo closed 9 months ago

JanuNoo commented 9 months ago

Hello,

I want to test a websocket server for fragmentation compliance using this library. As I can read from rfc 6455:

" A fragmented message consists of a single frame with the FIN bit clear and an opcode other than 0, followed by zero or more frames with the FIN bit clear and the opcode set to 0, and terminated by a single frame with the FIN bit set and an opcode of 0 " So I tried doing the following:

ws.sendFragmentedFrame(Opcode.BINARY, ByteBuffer.wrap(new byte[]{1,2,3}), false); ws.sendFragmentedFrame(Opcode.CONTINUOUS, ByteBuffer.wrap(new byte[]{4,5,6}), false); ws.sendFragmentedFrame(Opcode.CONTINUOUS, ByteBuffer.wrap(new byte[]{7,8,9}), true);

where ws is an instance of a class that extends WebSocketClient.

but got the following error:

"Only Opcode.BINARY or Opcode.TEXT are allowed".

Any ideas what I am doing wrong? Thanks

JanuNoo commented 9 months ago

Nevermind. It seems that if you do the following:

ws.sendFragmentedFrame(Opcode.BINARY, ByteBuffer.wrap(new byte[]{1,2,3}), false); ws.sendFragmentedFrame(Opcode.BINARY, ByteBuffer.wrap(new byte[]{4,5,6}), false); ws.sendFragmentedFrame(Opcode.BINARY, ByteBuffer.wrap(new byte[]{7,8,9}), true);

internally it sends the frames as rfc 6455 dictates.