This commit is contained in:
griffi-gh 2023-01-31 02:51:54 +01:00
parent 6f45a0ee77
commit 5c3062d13f
4 changed files with 26 additions and 0 deletions

View file

@ -10,5 +10,6 @@ glam = { version = "0.22", features = ["debug-glam-assert", "fast-math", "serde"
strum = { version = "0.24", features = ["derive"] } strum = { version = "0.24", features = ["derive"] }
bincode = { version = "2.0.0-rc", default_features = false, features = ["std", "serde"] } bincode = { version = "2.0.0-rc", default_features = false, features = ["std", "serde"] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
anyhow = "1.0"
bracket-noise = "0.8" bracket-noise = "0.8"
#laminar = "0.5.0" #laminar = "0.5.0"

View file

@ -1 +1,3 @@
pub mod messages; pub mod messages;
pub mod client;
pub mod server;

View file

@ -0,0 +1,23 @@
use std::net::{UdpSocket, SocketAddr};
use super::messages::ClientToServerMessage;
const BINCODE_CONFIG: bincode::config::Configuration<bincode::config::LittleEndian, bincode::config::Varint, bincode::config::SkipFixedArrayLength> = bincode::config::standard()
.with_little_endian()
.with_variable_int_encoding()
.skip_fixed_array_length();
pub struct Client {
socket: UdpSocket
}
impl Client {
pub fn bind(addr: SocketAddr) -> anyhow::Result<Self> {
Ok(Self {
socket: UdpSocket::bind(addr)?
})
}
pub fn send(&self, message: ClientToServerMessage) -> anyhow::Result<()> {
let bytes = bincode::serde::encode_to_vec(message, BINCODE_CONFIG)?;
self.socket.send(&bytes)?;
Ok(())
}
}

View file