My personal project and infrastructure archive
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
nomicon/games/rstnode/rst-server/src/net/mod.rs

43 lines
854 B

#![allow(unused)]
mod parser;
use async_std::{
net::UdpSocket,
sync::{Arc, RwLock},
task,
};
use rst_core::Id;
use std::{collections::BTreeMap, net::SocketAddr};
pub struct ServerEndpoint {
socket: UdpSocket,
bind: String,
clients: RwLock<BTreeMap<Id, Client>>,
}
impl ServerEndpoint {
pub async fn new(bind: &str) -> Arc<Self> {
let socket = UdpSocket::bind(bind).await.unwrap();
Arc::new(Self {
socket,
bind: bind.into(),
clients: Default::default(),
})
}
pub async fn listen(self: &Arc<Self>) {
let mut buf = vec![0; 1024];
info!("Listening for connections on {}", self.bind);
loop {
let (_, peer) = self.socket.recv_from(&mut buf).await.unwrap();
}
}
}
pub struct Client {
addr: SocketAddr,
}