vi/websocat

provide interface that accepts `Opts` and `std::process::Stdio`

Closed this issue · 3 comments

  1. replace all println! to writeln! e.g.
  2. helper function to parse & validate args as running from command line
  3. helper function to validate options with Opt struct
  4. accept two Option<Stdio>, and a ValidatedOpt (maybe)
  5. pipe stdin, stdout
vi commented

What is your use case?

What Command do you mean? std::process::Command?

Do you mean full Websocat functionality (UDP, overlays, multiplexing, UNIX sockets) or just basic client mode like websocat wss://my.site/?

What is your use case?

pipe fio's stdout to a websocket client

fio is a I/O tester program, which may cost much of time, I want pipe it's output to websocat as websocket server, and receive it's stdout in website (websocket client) without wait for it completes

What Command do you mean? std::process::Command?

sure, which meant that websocat should accept alternative Stdio

Do you mean full Websocat functionality (UDP, overlays, multiplexing, UNIX sockets) or just basic client mode like websocat wss://my.site/?

websocat --text --concap 1 --exit-on-eof ws-l:127.0.0.1:11451 reuse-raw:stdio:

from your answer in 2019

use std::process::{Command, Stdio};

use anyhow::Result;

fn main() -> Result<()> {
    let mut out = Command::new("./websocat")
        .arg("--text")
        .arg("--conncap")
        .arg("1")
        .arg("--exit-on-eof")
        .arg("ws-l:127.0.0.1:11451")
        .arg("reuse-raw:stdio:")
        .stdin(Stdio::piped())
        .spawn()?;

    let _ = Command::new("fio")
        .arg("--size=2048M")
        .arg("--name=randrw")
        .arg("--output-format=normal")
        .arg("--filename=0.txt")
        .arg("--eta-newline=1")
        .arg("--time_based")
        .arg("--runtime=120")
        .stdout(out.stdin.take().unwrap())
        .spawn()?
        .wait()?;

    std::thread::sleep(std::time::Duration::from_secs(1));
    out.kill()?; // websocat did not stop after fio exits

    Ok(())
}

update: nevermind, now I bind a WsServer and read lines with linereader

vi commented

Note: rust-websocket project (websocket crate) is semi-abandoned and depends on outdated dependency hyper 0.10.

You should try tungstenite instead.