this is a light weight tcp connection manager, including client and server side functions to communicate at high speed long living stable connctions with message que written in Rust.
put carte name and version in your cargo.toml file under dependencies.
bash
postoffice = "*"
```rust
use postoffice::{Request,Response,server};
fn handler(req: Request) -> Result
fn auth(token:server::auth::Token) -> bool { println!("token : {:?}",token); return true; }
fn main(){ let key = "8cfb30b34977529853bbe46afdbbd5ae".to_string(); let address = String::from("127.0.0.1:5200"); server::init(address,key,handler,auth); }
```
```rust
use postoffice::client::{gettestmessage,getrandomconnectionid,startconnection,send_message};
fn main(){
let key = "8cfb30b34977529853bbe46afdbbd5ae".tostring(); let connectionid = client::getrandomconnectionid(); let addr = "127.0.0.1:5200".tostring();
match startconnection(&connectionid,addr,key) { Ok()=>{ //println!("connection establishged"); }, Err()=>{ common::error("failed start connection"); } }
let message = gettestmessage(8); match sendmessage(&connectionid, message.clone(), false) { Ok(response)=>{ println!("response final : {:#?}",response); }, Err(_)=>{ common::error("request-failed"); } }
}
```
Please make sure to update tests as appropriate.
MIT