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 root root 4096 Jul 3 00:34 .\ndrwx------ 4 root root 4096 Jul 3 00:34 ..\n-rw-rw-r-- 1 root root 107 Jul 3 00:34 data.txt\n---\npeakstone file-server fi
[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=48629\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=48629\n"}
[turn 5] write_file({"node": "server", "path": "server.py", "content": "#!/usr/bin/env python3\nimport os\nfrom http.server import HTTPServer, SimpleHTTPRequestHandler\n\nclass FileRequestHandler(SimpleHTTPRequestHandler) -> {"ok": true, "node": "server", "path": "server.py"}
[turn 6] write_file({"node": "client", "path": "client.py", "content": "#!/usr/bin/env python3\nimport os\nimport urllib.request\n\ndef main():\n host = os.environ.get('PEER_SERVER_HOST', 'localhost')\n port = os.e) -> {"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": []}