examples/http_server.py: Introduce main() function.

Allows to re-run code if it was imported as a module (e.g., on bare-metal
ports).
This commit is contained in:
Paul Sokolovsky 2016-04-02 20:57:58 +03:00
parent aa3fb7b387
commit c07a03a36d

View File

@ -10,6 +10,7 @@ HTTP/1.0 200 OK
Hello #%d from MicroPython!
"""
def main(use_stream=False):
s = socket.socket()
ai = socket.getaddrinfo("127.0.0.1", 8080)
@ -29,7 +30,7 @@ while True:
print("Client address:", client_addr)
print("Client socket:", client_s)
print("Request:")
if 0:
if use_stream:
# MicroPython socket objects support stream (aka file) interface
# directly.
print(client_s.read(4096))
@ -40,3 +41,6 @@ while True:
client_s.close()
counter += 1
print()
main()