Very primitive UDP receive
parent
a8caae68c3
commit
6bb2678eb5
|
@ -69,6 +69,21 @@ async fn handle_udp_send () -> Response <Body>
|
||||||
status_reply (StatusCode::OK, "ok\n")
|
status_reply (StatusCode::OK, "ok\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn handle_udp_recv () -> Response <Body>
|
||||||
|
{
|
||||||
|
use tokio::net::UdpSocket;
|
||||||
|
|
||||||
|
let mut sock = UdpSocket::bind (SocketAddr::from (([0,0,0,0], 4001))).await.unwrap ();
|
||||||
|
|
||||||
|
let mut buffer = vec! [0u8; 4096];
|
||||||
|
|
||||||
|
let (bytes_received, _addr) = sock.recv_from (&mut buffer [..]).await.unwrap ();
|
||||||
|
|
||||||
|
buffer.truncate (bytes_received);
|
||||||
|
|
||||||
|
status_reply (StatusCode::OK, buffer)
|
||||||
|
}
|
||||||
|
|
||||||
async fn handle_all (req: Request <Body>, state: Arc <ServerState>)
|
async fn handle_all (req: Request <Body>, state: Arc <ServerState>)
|
||||||
-> Result <Response <Body>, Infallible>
|
-> Result <Response <Body>, Infallible>
|
||||||
{
|
{
|
||||||
|
@ -84,6 +99,9 @@ async fn handle_all (req: Request <Body>, state: Arc <ServerState>)
|
||||||
else if uri == "/udp_send" {
|
else if uri == "/udp_send" {
|
||||||
Ok (handle_udp_send ().await)
|
Ok (handle_udp_send ().await)
|
||||||
}
|
}
|
||||||
|
else if uri == "/udp_recv" {
|
||||||
|
Ok (handle_udp_recv ().await)
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
Ok (status_reply (StatusCode::OK, "Hi\n"))
|
Ok (status_reply (StatusCode::OK, "Hi\n"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue