vi / websocat

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

one-argument mode and two-argument mode behave differently #8

Closed alkorsan closed 6 years ago

alkorsan commented 6 years ago

using two-argument mode: this will send my multi-line payload as 1 message and will retain \n . that is good

$  printf 'A\nB\n' | websocat - ws://echo.websocket.org/
A
B

now look please when using one-argument mode: this will send 2 messages, but it considers that 1 line is 1 message! and it will remove the \n from every message sent.

$  printf 'A\nB\n' | websocat ws://echo.websocket.org/
A
B

why both examples don't have the same behavior? can one-argument mode have the same behavior like two-argument mode? or am I missing something?

alkorsan commented 6 years ago

the owner answered me in the public chat for the same question, I past the answer here:

It was already discussed before.

1-arg 2-arg
text binary
2 messages 1 message
no newlines with newlines

1-arg mode is user-friendly mode, 2-arg mode is raw mode. There should be a way to send both messages without newline and with newline. It is not certain which mode should be default. But I expect WebSocket messages to be typically 1-line serialized JSON (without a newline at the end). Maybe in future I also add special JSON powers to websocat, so that you can specify {a:5, b:qwer} and it would send {"a":5, "b":"qwer"} (or something like that).

me:

is it correct to say that websocat uses \n as a delimiter? the json may contain \n, or the server may force you to send \n

JSON may only contain \n as a whitespace, not as a proper content.

why it is not EOF the delimiter?

What if you want to send multiple messages?