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] 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 MyHandler(http.serve) -> {"ok": true, "node": "server", "path": "server.py"}
[turn 3] write_file({"node": "client", "path": "client.py", "content": "#!/usr/bin/env python3\nimport urllib.request\nimport os\n\nHOST = os.environ.get('PEER_SERVER_HOST', 'localhost')\nPORT = int(os.environ.get('PEER_) -> {"ok": true, "node": "client", "path": "client.py"}
[turn 4] verify({}) -> {"passed": true, "checks": [{"name": "client received the exact server bytes", "ok": true, "detail": "expected 107 bytes; client wrote 107"}], "launch_errors": []}