env-01-file-server
1.000
Challenge · difficulty 3/5
# HTTP file server + client Two nodes are provisioned on a private, no-internet network: - **server** — must serve files from its working directory over HTTP. It listens on the port given in the `PORT` environment variable. The file `data.txt` already exists in its working directory. - **client** — must fetch `data.txt` from the server and write the **exact bytes** it receives to a file named `result.txt` in its own working directory. The server's address is provided as the `PEER_SERVER_HOST` and `PEER_SERVER_PORT` environment variables. Write the program for each node: - On **server**, create `server.py` (launched as `python server.py`). - On **client**, create `client.py` (launched as `python client.py`). The task is solved when the client's `result.txt` contains exactly the bytes of the server's `data.txt`. Only the Python standard library is available (no internet, no pip).
Proposed solution
[turn 1] list_nodes({}) -> {"nodes": [{"name": "server", "provides": "python server.py", "ports": [8080], "needs": []}, {"name": "client", "provides": "python client.py", "ports": [], "needs": ["server"]}]}
[turn 2] run({"node": "server", "cmd": "ls -la && echo \"---\" && cat data.txt 2>/dev/null || echo \"data.txt not found\""}) -> {"rc": 0, "output": "total 12\ndrwxrwxr-x 2 psc psc 4096 Jul 2 14:38 .\ndrwx------ 4 psc psc 4096 Jul 2 14:38 ..\n-rw-rw-r-- 1 psc psc 107 Jul 2 14:38 data.txt\n---\npeakstone file-server fixture\
[turn 3] run({"node": "server", "cmd": "echo \"PORT=$PORT\" && echo \"PEER_SERVER_HOST=$PEER_SERVER_HOST\" && echo \"PEER_SERVER_PORT=$PEER_SERVER_PORT\""}) -> {"rc": 0, "output": "PORT=58287\nPEER_SERVER_HOST=\nPEER_SERVER_PORT=\n"}
[turn 4] run({"node": "client", "cmd": "echo \"PORT=$PORT\" && echo \"PEER_SERVER_HOST=$PEER_SERVER_HOST\" && echo \"PEER_SERVER_PORT=$PEER_SERVER_PORT\""}) -> {"rc": 0, "output": "PORT=\nPEER_SERVER_HOST=127.0.0.1\nPEER_SERVER_PORT=58287\n"}
[turn 5] write_file({"node": "server", "path": "server.py", "content": "#!/usr/bin/env python3\n\"\"\"HTTP file server that serves files from the current directory.\"\"\"\n\nimport os\nfrom http.server import HTTPServer,) -> {"ok": true, "node": "server", "path": "server.py"}
[turn 6] write_file({"node": "client", "path": "client.py", "content": "#!/usr/bin/env python3\n\"\"\"HTTP client that fetches data.txt from the server and saves it.\"\"\"\n\nimport os\nimport urllib.request\n\ndef main() -> {"ok": true, "node": "client", "path": "client.py"}
[turn 7] verify({}) -> {"passed": true, "checks": [{"name": "client received the exact server bytes", "ok": true, "detail": "expected 107 bytes; client wrote 107"}], "launch_errors": []}