examples/http_server.py: Bind to 0.0.0.0, to be accessible from other hosts.

This is helpful when running on deeply embedded targets, but may be
"security risk". Caveat emptor.
This commit is contained in:
Paul Sokolovsky 2016-04-02 23:14:19 +03:00
parent c07a03a36d
commit ec5f8db49d

View File

@ -13,14 +13,15 @@ Hello #%d from MicroPython!
def main(use_stream=False):
s = socket.socket()
ai = socket.getaddrinfo("127.0.0.1", 8080)
# Binding to all interfaces - server will be accessible to other hosts!
ai = socket.getaddrinfo("0.0.0.0", 8080)
print("Bind address info:", ai)
addr = ai[0][4]
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(addr)
s.listen(5)
print("Listening, connect your browser to http://127.0.0.1:8080/")
print("Listening, connect your browser to http://<this_host>:8080/")
counter = 0
while True: