websockets / wscat

WebSocket cat
MIT License
2.25k stars 223 forks source link

error: WebSocket was closed before the connection was established #126

Open danielmofer opened 4 years ago

danielmofer commented 4 years ago

I am cretaing a function to send the wscat to background and redirecting a FIFO file (mkfifo ppp) to drop the data to send by the streaming.

**sendToBackground**() {
wscat -c wss://example.url -w 86400 < **ppp**
sleep 20
}

sendToBackgound &

echo -n '{"method": "login", "params": {"algo": "BASIC","pKey": "ABCD","sKey": "ABCD"}}' > **ppp**

After execute it, I get the next error:

error: WebSocket was closed before the connection was established

What can I do to drop data to sedn by the wss ?

Thanks.

ghost commented 3 years ago

Did you manage to figure out a solution or workaround? This was helpful for me: https://github.com/websockets/wscat/issues/43

j1elo commented 3 years ago

I've seen this happen with other programs, such as when trying to pipe cat and grep in a shell script, and the cause is typically that the program is expecting an attached TTY and an stdin channel, when actually these are not available, causing an immediately closed pipe, and both sides to close abruptly.

It's trivial to reproduce this issue with Docker, because the docker run command can be given -t (attach TTY), -i (stdin), or none of them. With none of them, wscat prints the "error: WebSocket was closed before the connection was established" message and it doesn't work.

Related:

This tool simply seems exclusively designed with interactive use in mind. Which is not bad at all, especially given the money users paid for it :-) But given that a common usage pattern for CLI tools is to end up scripting them, I guess the minimum that could be done is warning in the README about not to do so with this one...