1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#![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,
}
|