A TCP-based connection that can send & receive serializable objects.
Add this to your Cargo.toml:
toml
[dependencies]
connection = "0.2.1"
You can create a Connection
by connecting like so:
```rust use connection::Connection;
async fn main() { let mut conn = Connection::connect("127.0.0.1:8080").await.unwrap(); } ```
You can use the Connection
to send and receive serializable objects:
```rust use connection::Connection; use serde::{Serialize, Deserialize};
/// A (de)serializable type shared between client and server
struct Message { id: u32, data: String, }
/// Code running client side async fn clientside(mut clientconn: Connection) { let message = Message { id: 1, data: "Hello, world!".to_string(), };
client_conn.write::
/// Code running server side
async fn serverside(mut serverconn: Connection) {
let message: Message = server_conn.read::