vi / websocat

Command-line client for WebSockets, like netcat (or curl) for ws:// with advanced socat-like functions
MIT License
6.74k stars 261 forks source link

Why do we send '\n' symbol after each text message? Is there any possibility to avoid that? #58

Closed yeryomenkom closed 4 years ago

yeryomenkom commented 4 years ago

@maxstreese

vi commented 4 years ago

Maybe you want binary mode -b?

Other influential options: --no-line, --no-fixups, --linemode-strip-newlines, --strict.

Depending of what you need (client mode, server mode, broadcast or just one client, uni- or bi-directional) I may recommend some specific command line to use.

Why

By default Websocat operates in text mode and tries to ensure that one line corresponds to one text message (both for sending and receiving).

yeryomenkom commented 4 years ago

Maybe you want binary mode -b?

No, I need to send text websocket frame. UPDATED: Here is a reference: https://tools.ietf.org/html/rfc6455 , "5.6. Data Frames"

I may recommend some specific command line to use.

Thanks) I have a server that accepts websocket connections and somehow responds to the commands. The server is tested via integration test and works as expected. But, when I try to connect to that server via 'websocat', the issue with '\n' symbol occurs.

yeryomenkom commented 4 years ago

So, --linemode-strip-newlines does the job. Thank you for your help!

yeryomenkom commented 4 years ago

Weird, but I do not see that flag in -help. Do I miss something?

vi commented 4 years ago

--help=full?

Do you think this is important enough option to be moved to short help?

yeryomenkom commented 4 years ago

Do you think this is important enough option to be moved to short help?

I think yes. Honestly speaking, I would even change the default behavior for sending text frames. Websocket protocol specifies nothing regarding the new line symbol in the end of text frame. So, at least for me, it was very confusing to realize that 'websocat' adds that symbol by default.

vi commented 4 years ago

adds that symbol by default

More like "not removes the extraneous symbol by default". Newline is typically present in user input. It gets inserted when one presses Enter.

You can send one message without \n and without --linemode-strip-newlines as well:

$ printf 'qwerty' | websocat  ws://...
[WARN  websocat::line_peer] Sending possibly incomplete line.
yeryomenkom commented 4 years ago

More like "not removes the extraneous symbol by default". Newline is typically present in user input. It gets inserted when one presses Enter.

I see. But in what case user may want to insert that symbol? I think user presses enter to send text frame. When I type mkdir lol and press Enter I expect that "lol" directory will be created. Not 'lol\n'.

You can send one message without \n and without --linemode-strip-newlines as well:

Maybe I can, but I will never do)