websocat icon indicating copy to clipboard operation
websocat copied to clipboard

Websocat server with base64 encoded file

Open LatentLag opened this issue 3 years ago • 4 comments

My issue is that I cannot serve a base64 file created with websocat, so that I can receive it as binary again.

After creating a file with the command

$ websocat_win64.exe --base64 --binary ws://127.0.0.1:8080 > my.b64

I try to serve the file:

$ websocat_win64.exe --base64 --binary ws-listen:127.0.0.1:8081 readfile:my.b64
websocat: Unfortunately, serving multiple clients without --exit-on-eof (-E) or with -U option is prone to socket leak in this websocat version
[ERROR websocat::ws_peer] Failed to decode user-supplised base64 buffer. Sending message as is.
[ERROR websocat::ws_peer] Failed to decode user-supplised base64 buffer. Sending message as is.

(The last error is repeated numerous times)

I was expecting to receive the data in the file after base64 decoding, in binary served to my own client program but am receiving the base 64 text.

The line length of the base 64 file is between 50 and 800KB.

LatentLag avatar Oct 13 '22 10:10 LatentLag

Removing the --binary option and adding a large buffer -B 10000000 made the program work as desired.

LatentLag avatar Oct 13 '22 10:10 LatentLag

Are you sure it works as desired after removing --binary? --base64 is probably meaningless without either --binary or --binary-prefix. Or have you decoded the file manually, outside of Websocat?

Small buffer size may have indeed caused input file to be split to multiple chunks prior to base64 decode, causing multiple broken WebSocket message instead of one large WebSocket message with the entire file.

vi avatar Oct 13 '22 13:10 vi

Are you sure it works as desired after removing --binary? --base64 is probably meaningless without either --binary or --binary-prefix. Or have you decoded the file manually, outside of Websocat?

Small buffer size may have indeed caused input file to be split to multiple chunks prior to base64 decode, causing multiple broken WebSocket message instead of one large WebSocket message with the entire file.

Working without --binary

For context, I'm using the --base64 to record and playback protobuf messages delimited by the WebSocket end of message flag. As best as I can check a 700kB deserialized protobuf message quickly it seems to decode correctly when the --binary option is removed.

I also ran the playback through: $ websocat -B 5000000 --base64 ws://127.0.0.1:8081 > my-playback.b64 And compared the hash of my.b64 to my-playback.b64, which matched.

Decoding outside of Websocat

I converted the my.b64 file to a length delimited protobuf file in python. Then I processed that file. The output matched processing my.b64 directly.

It would be great to have more intelligent chunking when dealing with a buffer smaller than a line of base 64 encoded.

LatentLag avatar Oct 14 '22 00:10 LatentLag

You can control chunking by using large buffer size, line2msg: overlay and --base64 option. Each line of input file will be converted to a WebSocket message.

vi avatar Oct 14 '22 07:10 vi