MCPcopy Create free account
hub / github.com/bytecodealliance/wstd / main

Function main

examples/tcp_echo_server.rs:6–22  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4
5#[wstd::main]
6async fn main() -> io::Result<()> {
7 let listener = TcpListener::bind("127.0.0.1:8080").await?;
8 println!("Listening on {}", listener.local_addr()?);
9 println!("type `nc localhost 8080` to create a TCP client");
10
11 let mut incoming = listener.incoming();
12 while let Some(stream) = incoming.next().await {
13 let stream = stream?;
14 println!("Accepted from: {}", stream.peer_addr()?);
15 wstd::runtime::spawn(async move {
16 // If echo copy fails, we can ignore it.
17 let _ = io::copy(&stream, &stream).await;
18 })
19 .detach();
20 }
21 Ok(())
22}

Callers

nothing calls this directly

Calls 4

spawnFunction · 0.85
copyFunction · 0.85
incomingMethod · 0.80
nextMethod · 0.45

Tested by

no test coverage detected