Added how to run `simple_host` and `simple_client` in readme
This commit is contained in:
parent
b552b5760b
commit
d806ad3e5c
|
@ -1,5 +1,31 @@
|
|||
use commander_kernel::tcp::{ConnectOptions, StreamClient};
|
||||
use commander_kernel::Payload;
|
||||
use prost::Message;
|
||||
use std::io::Cursor;
|
||||
include!(concat!(env!("OUT_DIR"), "/simple_message.rs"));
|
||||
|
||||
fn main() {}
|
||||
fn main() {
|
||||
let connect_options = ConnectOptions::new(String::from("127.0.0.1"), 6661);
|
||||
let client = StreamClient::new(connect_options);
|
||||
|
||||
let message = MessageObject {
|
||||
text: "hello from simple_client".to_string(),
|
||||
};
|
||||
|
||||
let payload = Payload {
|
||||
route: String::from("route/example"),
|
||||
body: message.encode_to_vec(),
|
||||
};
|
||||
|
||||
let ret = client.send(payload.encode_to_vec());
|
||||
|
||||
match ret {
|
||||
Ok(d) => {
|
||||
let str = String::from_utf8(d).expect("could not decode");
|
||||
println!("client got: {}", str);
|
||||
}
|
||||
Err(_) => {
|
||||
panic!("error unpacking client response")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
12
readme.md
12
readme.md
|
@ -12,5 +12,17 @@ For examples on how to use it, see:
|
|||
1. the tests under `tests/`
|
||||
2. the `simple_host` and `simple_client` under `examples/`
|
||||
|
||||
I you want to see the examples running, do this from two shells (current directory is the root of the `commander` repo):
|
||||
|
||||
```bash
|
||||
# shell 1
|
||||
cargo run --example simple_host
|
||||
|
||||
# shell 2
|
||||
cargo run --example simple_client
|
||||
|
||||
# shell 2 outputs: client got: Hello from Example. Got: hello from simple_client
|
||||
```
|
||||
|
||||
### Nextgen
|
||||
I am currently looking into using the rsa crate: `rsa = { version = "0.9", features = ["sha2", "pem"] }` for simple encryption/decrypting and message signing. More on this later.
|
Loading…
Reference in New Issue