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

How to transfer text and binary data in one connection? #20

Closed ssmmhh closed 4 years ago

ssmmhh commented 6 years ago

Thank you for your great tools. ^^

I want to use the Web SocketAPI. (via TCP) ex) websocat tcp-l:127.0.0.1:4554 ws://123.456.789.012:8100/api/v1/fileupload

The API works with three commands:

  1. Deliver file information in json format. {"action":"create", "filename":"test.png"} -> text mode
  2. Deliver the actual contents of the file (test,png) -> binary mode
  3. end point of the file. {"action":"stop"} ->text mode

It determines the execution mode and allows only one to be used. (-t or -b) Can I transfer binary data or text data while connected? (I am using the Windows environment.)

vi commented 6 years ago

Unfortunately, sending both text and binary WebSocket messages is unsupported by current design of websocat.

There is also no obvious workaround. You can help by thinking and describing your opinions about how UX/workflow for mixing binary and text messages when forwarding from TCP would work. Note that status of being a text or binary message is only one part of the problem. Other part is how to find where contents of the file ends and the next text message begins. It would probably involve two TCP sockets or some prefixes/delimiters. To be a part of Websocat, it should be universal (allowing multiple text -> binary -> text transitions, supporting arbitrary (not necessary JSON) messages, and so on. Otherwise it's better to make a separate tool for the file upload.

What is that service with such API? Maybe there is some dedicated tool for it? Or it is the time to make such tool?