A high-level UDP Socket that allows for writing and reading (de)serializable values
Add this to your Cargo.toml:
toml
[dependencies]
sockit = "0.2.0"
You can create a Socket by binding it to an address like so:
```rust
async fn main() { let socket = sockit::UdpSocket::bind("127.0.0.1:0").await?; } ```
You can use the Socket to send and receive serializable objects:
```rust use sockit::UdpSocket; 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 clientsocket: UdpSocket) { let message = Message { id: 1, data: "Hello, world!".to_string(), };
client_socket.write::
/// Code running server side
async fn serverside(mut serversocket: UdpSocket) {
let message: Message = server_socket.read::