diff --git a/kubi-shared/Cargo.toml b/kubi-shared/Cargo.toml index 6568ab7..0cae1ee 100644 --- a/kubi-shared/Cargo.toml +++ b/kubi-shared/Cargo.toml @@ -10,5 +10,6 @@ glam = { version = "0.22", features = ["debug-glam-assert", "fast-math", "serde" strum = { version = "0.24", features = ["derive"] } bincode = { version = "2.0.0-rc", default_features = false, features = ["std", "serde"] } serde = { version = "1.0", features = ["derive"] } +anyhow = "1.0" bracket-noise = "0.8" #laminar = "0.5.0" diff --git a/kubi-shared/src/networking.rs b/kubi-shared/src/networking.rs index ba63992..8a4e7ed 100644 --- a/kubi-shared/src/networking.rs +++ b/kubi-shared/src/networking.rs @@ -1 +1,3 @@ pub mod messages; +pub mod client; +pub mod server; diff --git a/kubi-shared/src/networking/client.rs b/kubi-shared/src/networking/client.rs new file mode 100644 index 0000000..d112490 --- /dev/null +++ b/kubi-shared/src/networking/client.rs @@ -0,0 +1,23 @@ +use std::net::{UdpSocket, SocketAddr}; +use super::messages::ClientToServerMessage; + +const BINCODE_CONFIG: bincode::config::Configuration = 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 { + 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(()) + } +} diff --git a/kubi-shared/src/networking/server.rs b/kubi-shared/src/networking/server.rs new file mode 100644 index 0000000..e69de29