MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / try_echo

Function try_echo

e2e/rust/tests/port_forward.rs:118–139  ·  view source on GitHub ↗

Attempt to send `hello-nav\n` to the echo server and read the response.

(port: u16)

Source from the content-addressed store, hash-verified

116
117/// Attempt to send `hello-nav\n` to the echo server and read the response.
118async fn try_echo(port: u16) -> Result<String, String> {
119 let mut stream = TcpStream::connect(format!("127.0.0.1:{port}"))
120 .await
121 .map_err(|e| format!("connect: {e}"))?;
122
123 stream
124 .write_all(b"hello-nav\n")
125 .await
126 .map_err(|e| format!("write: {e}"))?;
127
128 let mut buf = vec![0u8; 4096];
129 let n = tokio::time::timeout(Duration::from_secs(10), stream.read(&mut buf))
130 .await
131 .map_err(|_| "read timeout".to_string())?
132 .map_err(|e| format!("read: {e}"))?;
133
134 let response = String::from_utf8_lossy(&buf[..n])
135 .trim_end_matches(['\r', '\n'])
136 .to_string();
137
138 Ok(response)
139}

Callers 1

port_forward_echoFunction · 0.85

Calls 2

connectFunction · 0.85
readMethod · 0.45

Tested by

no test coverage detected