websocat icon indicating copy to clipboard operation
websocat copied to clipboard

How to send one message split over several partial frames?

Open faceless2 opened this issue 3 years ago • 8 comments

I'm trying to use websocat as a client to test a server WebSocket implementation which is designed to take large messages (both text and binary).

But I seem to be unable to persuade websocat to send either text or binary as one message, split over several frames. Large content is sent as several messages of 64k each, and if I add --one-message I get one message... of 64k, with the rest of the data dropped. What I was expecting was one large message sent over several 64kb frames.

I can't see any mention of this in the issues or docs, which kind of surprises me. Specifically, for the benfit of anyone searching the issues like I've been, I believe I want to send a sequence of frames (or chunks) with the "fin" flag set on the final one.

Is this possible with websocat?

faceless2 avatar Dec 07 '21 13:12 faceless2

FIN:  1 bit

Indicates that this is the final fragment in a message.  The first
fragment MAY also be the final fragment.

Today I learned that WebSocket messages may be fragmented over multiple frames (and that "message" and "frame" are distinct things in general).

Unfortunately, current version of Websocket does not expose frame size as configurable parameter. Next major version will probably expose WebSocketConfig, but it is rather far from ready at the moment.

vi avatar Dec 07 '21 15:12 vi

Well, glad I could help :-) Thanks for the quick response - it's a great tool, I'll find something else to test the fragmentation.

faceless2 avatar Dec 07 '21 15:12 faceless2

If you are OK with meddling with source code, you may try websocat3 branch and manually modify the config in source code.

Unfortunately, normal high-level Websocat command lines are not yet supported there, you need to use special tree format. Here is a client example:

websocat  '[datagrams @ stdio]' '[wsc uri=ws://ws.vi-server.org/mirror]'

I can also expose frame size option and make a pre-built executable for you if it is problematic. You need to specify your platform in this case.

vi avatar Dec 07 '21 15:12 vi

Thank you. But I'll dig up some tools in a language I'm more familiar with for this bit, and am happy to wait for version 3.

faceless2 avatar Dec 07 '21 15:12 faceless2

I expect implementing such testing tool to be rather simple in JavaScript or Golang, maybe multiple other general-purpose languages.

vi avatar Dec 07 '21 15:12 vi

Could you provide example how to force websocat to send message in fragments? I tried to modify param -B and send very large message but I am not still not sure if message is really fragmented by websocat

michaldo avatar Jun 15 '22 11:06 michaldo

With small -B it would be small WebSocket messages (in small frames), not large messages with multiple small frames. Websocat1 does not support setting distinct sizes.

Specifying distinct buffer sizes can be added to Websocat3, which use other underlying WebSocket library.

vi avatar Jun 15 '22 12:06 vi

My experiment shows that small -B cause a few separated messages are sent, not one fragmented message:

https://datatracker.ietf.org/doc/html/rfc6455

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.

michaldo avatar Jun 17 '22 09:06 michaldo