Add tracing
This commit is contained in:
parent
8c4c4d1d36
commit
ddf8e1ceb1
1 changed files with 8 additions and 1 deletions
|
|
@ -2,16 +2,22 @@ use std::collections::HashMap;
|
|||
use std::sync::Mutex;
|
||||
use std::{io, net::SocketAddr, str, sync::Arc};
|
||||
use tokio::{net::UdpSocket, sync::mpsc};
|
||||
use tracing::info;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
let sock = UdpSocket::bind("0.0.0.0:8080".parse::<SocketAddr>().unwrap()).await?;
|
||||
tracing_subscriber::fmt::try_init().unwrap();
|
||||
|
||||
let sock = UdpSocket::bind("0.0.0.0:1222".parse::<SocketAddr>().unwrap()).await?;
|
||||
info!("listening to new connections");
|
||||
|
||||
let r = Arc::new(sock);
|
||||
let s = r.clone();
|
||||
let (tx, mut rx) = mpsc::channel::<(Vec<u8>, SocketAddr)>(1_000);
|
||||
let storage = Arc::new(Mutex::new(HashMap::<String, String>::new()));
|
||||
|
||||
tokio::spawn(async move {
|
||||
info!("Send back!");
|
||||
while let Some((bytes, addr)) = rx.recv().await {
|
||||
let _ = s.send_to(&bytes, &addr).await.unwrap();
|
||||
}
|
||||
|
|
@ -19,6 +25,7 @@ async fn main() -> io::Result<()> {
|
|||
|
||||
let mut buf = [0; 1024];
|
||||
loop {
|
||||
info!("Recv loop");
|
||||
let (len, addr) = r.recv_from(&mut buf).await?;
|
||||
let message = str::from_utf8(&buf[..len]).unwrap().trim_matches('\n');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue