← run

env-01-file-server

1.000
1/1 tests· goal-state-env
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] 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] 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 SimpleHTTPRequestHan) -> {"ok": true, "node": "server", "path": "server.py"}
[turn 4] write_file({"node": "client", "path": "client.py", "content": "#!/usr/bin/env python3\nimport os\nimport urllib.request\n\nSERVER_HOST = os.environ.get('PEER_SERVER_HOST')\nSERVER_PORT = int(os.environ.get('PEER) -> {"ok": true, "node": "client", "path": "client.py"}
[turn 5] verify({}) -> {"passed": true, "checks": [{"name": "client received the exact server bytes", "ok": true, "detail": "expected 107 bytes; client wrote 107"}], "launch_errors": []}