# tcpr Simple and ergonomic TCP Client/Server with built in serialization/deserialization. ## Requirements - Rust: - [Official installation guide](https://www.rust-lang.org/tools/install) ## Installation `cargo add tcpr` ## Documentation This README provides a general overview. [Full crate documentation can be found here at docs.rs](https://docs.rs/tcpr/latest/tcpr/) ## Usage ### Basic Example ``` let (sx1, mut rx1) = channel::(4); let (sx2, mut rx2) = channel::(4); tokio::spawn(async move { loop { if let Some(message) = rx1.recv().await { // ... process message } } }); tokio::spawn(async move { loop { if let Some(message) = rx2.recv().await { // ... process message } } }); let server1 = TcpServer::new("127.0.0.1:1337", sx1, None); let server2 = TcpServer::new("127.0.0.1:1338", sx2, None); tokio::spawn(async move { server1.listen().await.unwrap(); }); tokio::spawn(async move { server2.listen().await.unwrap(); }); sleep(Duration::from_secs(3)).await; let client1 = TcpClient::connect("127.0.0.1:1337").await.unwrap(); let client2 = TcpClient::connect("127.0.0.1:1338").await.unwrap(); sleep(Duration::from_secs(3)).await; client1 .write(&Message::String("Hello".to_string())) .await .unwrap(); let mut map = HashMap::new(); map.insert("Hello".to_string(), "world".to_string()); sleep(Duration::from_secs(3)).await; client2.write(&Message::HashMap(map)).await.unwrap(); ``` `TcpServer` also exposes the option for a `error_sender` to propagates `TcpListenerError` to the receiver. ## License MIT | See `LICENSE.md` ## Project status I plan to maintain this project for the foreseeable future; although it is a base utility, so I would not expect any breaking changes.