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

Function echo_server_script

e2e/rust/tests/port_forward.rs:23–49  ·  view source on GitHub ↗

Python script that runs a single-threaded TCP echo server inside the sandbox. It prints `echo-server-ready` to stdout once listening, which the harness uses as the readiness marker.

(port: u16)

Source from the content-addressed store, hash-verified

21/// sandbox. It prints `echo-server-ready` to stdout once listening, which
22/// the harness uses as the readiness marker.
23fn echo_server_script(port: u16) -> String {
24 format!(
25 r"
26import socket, sys, signal
27signal.signal(signal.SIGHUP, signal.SIG_IGN)
28signal.signal(signal.SIGTERM, lambda *_: sys.exit(0))
29port = {port}
30sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
31sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
32sock.bind(('127.0.0.1', port))
33sock.listen(1)
34sock.settimeout(300)
35print('echo-server-ready', flush=True)
36try:
37 while True:
38 conn, _ = sock.accept()
39 data = conn.recv(4096)
40 if data:
41 conn.sendall(b'echo:' + data)
42 conn.close()
43except (socket.timeout, OSError):
44 pass
45finally:
46 sock.close()
47"
48 )
49}
50
51/// Create a sandbox with a TCP echo server, forward the port locally, send
52/// data through it, and verify the echoed response.

Callers 1

port_forward_echoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected