#tcp #server #command #query

linebased

Add a TCP query port to any program

9 releases

0.4.3 Feb 10, 2020
0.4.2 Feb 3, 2020
0.4.1 Jan 6, 2020
0.3.1 Aug 8, 2018
0.1.0 Jul 25, 2016

#28 in Authentication

Download history 67/week @ 2020-05-31 58/week @ 2020-06-07 57/week @ 2020-06-14 57/week @ 2020-06-21 17/week @ 2020-06-28 57/week @ 2020-07-05 98/week @ 2020-07-12 41/week @ 2020-07-19 20/week @ 2020-07-26 13/week @ 2020-08-02 24/week @ 2020-08-09 74/week @ 2020-08-16 113/week @ 2020-08-23 68/week @ 2020-08-30 57/week @ 2020-09-06 43/week @ 2020-09-13

293 downloads per month

MIT/Apache

21KB
433 lines

linebased

Build Status Crates.io

Drop-in TCP command server

About

Simple line-based TCP server for implementing command interfaces. There's no authentication or TLS support. Commands are handled synchronously as in Redis. The server uses an event loop internally to multiplex client connections.

Usage

This example is kept up-to-date on a best-effort basis. For a guaranteed acurate example, please see the docs.

#[tokio::main]
async fn main() {
    let config = Config::default()
        .host("127.0.0.1")
        .port(5555)
        .max_clients(32)
        .client_buf_size(1024);

    let mut server = Server::new(config, |query| {
        match query {
            "version" => String::from("0.1.0"),
            _ => String::from("unknown command"),
        }
    }).unwrap();

    server.run().await.unwrap();
}

This can be accessed over netcat like so:

jwilm@jwilm-desk ➜ nc localhost 5555
arst
unknown command
version
0.1.0

Dependencies

~3.5MB
~68K SLoC