websocat icon indicating copy to clipboard operation
websocat copied to clipboard

websocat4 does not send enter characters.

Open LaySoft opened this issue 8 months ago • 3 comments

I found a difference between websocat 1.13.0 and websocat4.

I pipe a command output to websocat like this:

ls -la | websocat wss://....

websocat 1.13.0 sends the enter characters (0x0a), but websocat4 don't.

What is the solution to make websocat4 also send the enter characters?

LaySoft avatar May 14 '25 16:05 LaySoft

Do you want each line to be a separate WebSocket message or the whole ls output to be in one WebSocket message?

You can use e.g. --separator-n=2 to force two newlines be the separator instead of just one. You'll need an extra command to supply the second newline though.

{ ls -la; echo;  } | websocat4 --separator-n=2 ws://127.0.0.1:1234/

As a workaround for specifically forcing each message to end with a newline, you can use other byte as a separator (e.g. zero byte) and substitute each \n with \n\0.

ls -la | sed -z 's!\n!\n\x00!g' | /opt/websocat4 -U0 ws://127.0.0.1:1234/

Why do you want the message to end with newlines?

Is it specifically for ls or actual scenario is more involved?

vi avatar May 14 '25 16:05 vi

Both websocat 1.13.0 and websocat4 send the output of the "ls -la" command line by line, each line is a separate message. This okay. But websocat4 does not send the enter at the end of each line, it truncates it. I want websocat4 to work the same way as websocat 1.13.0, i.e. to send the enters at the end of the lines.

LaySoft avatar May 14 '25 18:05 LaySoft

Implemented --separator-inline option to make it preserve the \ns.

vi avatar May 14 '25 18:05 vi