mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-23 20:38:21 -06:00
c
This commit is contained in:
parent
b855e57fae
commit
a61f419f3b
|
@ -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"
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
pub mod messages;
|
||||
pub mod client;
|
||||
pub mod server;
|
||||
|
|
23
kubi-shared/src/networking/client.rs
Normal file
23
kubi-shared/src/networking/client.rs
Normal 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(())
|
||||
}
|
||||
}
|
0
kubi-shared/src/networking/server.rs
Normal file
0
kubi-shared/src/networking/server.rs
Normal file
Loading…
Reference in a new issue