This crate provides a way of binding a TCP listener that will accept incoming
WebSocket connections. Additionally it provides an abstraction layer (see
Client
) for serializing and deserializing well-defined models.
```rust
struct Model {
payload: Vec
impl Into
impl TryFrom
fn try_from(payload: Vec<u8>) -> Result<Self, Self::Error> {
Ok(Self { payload })
}
}
fn handleclient(
client: Client
while let Some(msg) = rx.recv().await {
handle.send(msg).await.unwrap();
}
});
Ok(())
}
async fn main() -> Result<(), anyhow::Error> { let cancellation_token = CancellationToken::new();
let listener =
reception::Listener::<Model, Model>::bind(Default::default(), cancellation_token.clone())
.await?;
let handle = listener
.spawn_with_callback(cancellation_token.clone(), move |client| {
handle_client(client, cancellation_token.clone())
})
.await;
handle.await??;
Ok(())
} ```
See LICENSE.txt file.