websocat send json arrays
Hello, I tried using this link: https://stackoverflow.com/questions/48912184/wscat-commands-from-script-how-to-pass/48914019
however, it didn't work for me. I checked the readme and wondering if there's any solution maybe using readfile? but I can't find example file of hello.json. Please kindly help, thanks!
Do you want to just
- Connect to a Websocket server;
- Send single WebSocket message that contains a single JSON array;
- Disconnect from the server (without waiting for any reply message or sending additional messages)?
If yes, the readfile: specifier (or maybe just using redirection) may be appropriate, combined with a large buffer size (larger than maximum possible JSON array byte size).
Note that by default Websocat treats one line of input text as one WebSocket message. So your JSON arrays may just work if you use minified JSON representation, not indented multiline one.
Thank you!Vi, yes, I would like to do that, but I can't understand:
- (or maybe just using redirection): What does it mean? can you provide an example of that?
- So your JSON arrays may just work if you use minified JSON representation: can you also provide an illustration? Sorry Im newbie to this. Thanks!!
I don't understand what you are trying to do and what error do you get.
A minified JSON representation is like this:
[{"a":3,"b":null},{"a":null,"b":3.4}]
while human-readable is like this:
[
{
"a": 3,
"b": null
},
{
"a": null,
"b": 3.4
}
]
If you try to input the latter into Websocat, you typically get instead of one well-formed JSON message the multiple message like this:
[{"a": 3,"b": null},
(and so on)
This would cause server to reject those messages as invalid JSON arrays.
If you do indeed type (or otherwise provide) your message as one line, it should work. If not, describe it as a bug, with a proper "steps to reproduce" / "expected" / "actual" fields.
Thank you, I did it and got following warning: [WARN websocat::line_peer] Sending possibly incomplete line. however, I didn't se expected outcome. maybe something wrong.
Hi, Vi, When I return to stackoverflow, I saw you replied the following: @CharlesDuffy, The new websocat is released and exec: now has --exec-args option that makes all remaining options go into exec-ed program arguments.
I'd like to know more about how to do it, could you please explain to me? Thanks in adv.
You need to describe how you want to use Websocat (and Websockets in general) in more detail for me to help.
Sharing command line terminal sessions or scripts would also be helpful.
What I wanted to do is to pass json in command arrays or json files and pass them into ws:// connection, as stackoverflow told, I got the following error: bash: run_init: command not found
and my script is called as following: export -f run_init ./websocat --text $url sh-c:'exec bash -c run_init'
Any suggestions?