pull/1/head
dvkt 4 years ago
parent d596a143bb
commit bf2990121b

@ -30,13 +30,19 @@ async fn listen(addr: impl ToSocketAddrs) -> Result<()> {
Ok(())
}
async fn client_loop(stream: TcpStream) -> Result<()> {
async fn client_loop(mut stream: TcpStream) -> Result<()> {
let reader = BufReader::new(&stream);
let mut lines = reader.lines();
while let Some(line) = lines.next().await {
let line = line?;
if let Some(Ok(line)) = lines.next().await {
println!("-> client sent: {:?}", line);
respond(&mut stream, &line).await?;
}
Ok(())
}
async fn respond(stream: &mut TcpStream, selector: &str) -> Result<()> {
let response = format!("3You sent: {}", selector);
stream.write_all(response.as_bytes()).await?;
Ok(())
}

Loading…
Cancel
Save