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

How do I send two messages when connected? #84

Closed digitalcleavage closed 4 years ago

digitalcleavage commented 4 years ago

Hi, I have a very simple use case:

  1. Connect to a WSS
  2. Send a message in JSON which contains my auth. The server responds an authorization.
  3. Send one more message in JSON that tells the server what I'm trying to do.
  4. Store all of the data that streams back to a file.
  5. Do this until I kill the command.

I'm new to websockets and I can't seem to figure this out using websocat. The readme says this should all be doable but I am struggling to find the right commands to send.

digitalcleavage commented 4 years ago

I wanted to script this but I still can't figure out how to do it properly, but I did find a solution:

websocat wss://target.server/ > output.txt

Then I can manually enter commands on stdin the output goes to stdout

It's not as elegant as I would like, but it does the job.

vi commented 4 years ago

I wanted to script this ...

You can use something like chat(8) to drive Websocat.

You can also "websockify" existing program using websocat, which would output everything to output.txt after replying to authentication message, like this:

websocat -t wss://target.server/ exec:./my_program.sh

Each line my_program writes to stdout will be converted to a WebSocket message and each WebSocket message would be converted to one line on my_program's stdin.