env-01-file-server
0.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] write_file({"node": "server", "path": "server.py", "content": "#!/usr/bin/env python3\nimport http.server\nimport socketserver\nimport os\n\nPORT = int(os.environ.get('PORT', 8080))\n\nclass FileHandler(http.ser) -> {"ok": true, "node": "server", "path": "server.py"}
[turn 1] write_file({"node": "client", "path": "client.py", "content": "#!/usr/bin/env python3\nimport socket\nimport os\n\nSERVER_HOST = os.environ.get('PEER_SERVER_HOST', 'localhost')\nSERVER_PORT = int(os.environ.get() -> {"ok": true, "node": "client", "path": "client.py"}
[turn 2] verify({}) -> {"passed": false, "checks": [{"name": "client received the exact server bytes", "ok": false, "detail": "expected 107 bytes; client wrote 280 \u2014 mismatch"}], "launch_errors": []}
[turn 3] read_file({"node": "server", "path": "data.txt"}) -> {"content": "peakstone file-server fixture\nline two: 1234567890\nline three: the quick brown fox jumps over the lazy dog\n"}
[turn 3] read_file({"node": "client", "path": "result.txt"}) -> {"content": " 200 OK\nServer: SimpleHTTP/0.6 Python/3.12.13\nDate: Thu, 02 Jul 2026 23:45:55 GMT\nContent-type: text/plain\nContent-Length: 107\nLast-Modified: Thu, 02 Jul 2026 23:45:55 GMT\n\npeaksto
[turn 4] write_file({"node": "client", "path": "client.py", "content": "#!/usr/bin/env python3\nimport socket\nimport os\n\nSERVER_HOST = os.environ.get('PEER_SERVER_HOST', 'localhost')\nSERVER_PORT = int(os.environ.get() -> {"ok": true, "node": "client", "path": "client.py"}
[turn 5] verify({}) -> {"passed": false, "checks": [{"name": "client received the exact server bytes", "ok": false, "detail": "expected 107 bytes; client wrote 280 \u2014 mismatch"}], "launch_errors": ["server:8080 never be
[turn 6] run({"node": "server", "cmd": "python server.py &"}) -> {"rc": 0, "output": ""}
[turn 7] run({"node": "server", "cmd": "sleep 1 && curl -s http://localhost:8080/data.txt"}) -> {"rc": 7, "output": ""}
[turn 8] run({"node": "server", "cmd": "ps aux | grep python"}) -> {"rc": 0, "output": "nobody 1672 0.0 0.0 112260 3212 ? Ssl Jun23 0:00 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal\nroot 668984
[turn 9] run({"node": "server", "cmd": "python server.py"}) -> {"rc": 1, "output": "Traceback (most recent call last):\n File \"/tmp/psenv-env-01-file-server-4darahkr/server/server.py\", line 16, in <module>\n with socketserver.TCPServer((\"\", PORT), FileHan
[turn 10] run({"node": "server", "cmd": "lsof -i :8080"}) -> {"rc": 1, "output": ""}