Victorem - easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust.
toml
[dependencies]
victorem = "*"
```rust use victorem; use std::time::{Duration, Instant};
fn main() { let mut client = victorem::ClientSocket::new("1111", "127.0.0.1:2222").unwrap(); let mut id: u32 = 0; let mut timer = Instant::now(); let period = Duration::frommillis(100); loop { if timer.elapsed() > period { timer = Instant::now(); id += 1; let _ = client .send(format!("Ping {}", id).intobytes()); } let _ = client .recv() .map(|v| String::fromutf8(v).unwrapor(String::new())) .map(|s| println!("From Server: {}", s)); } } ```
```rust use victorem; use std::net::SocketAddr; use std::time::Duration;
struct PingPongGame { id: u32, }
impl victorem::Game for PingPongGame {
fn handlecommand(
&mut self,
deltatime: Duration,
commands: Vec
fn draw(&mut self, delta_time: Duration) -> Vec<u8> {
self.id += 1;
format!("Pong {} {:?}", self.id, delta_time).into_bytes()
}
}
fn main() { let mut server = victorem::GameServer::new( PingPongGame { id: 0 }, "2222", ).unwrap(); server.run(); } ```