From aa3fb7b3876d868b0070ca85d97f700e0c2dec20 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 2 Apr 2016 20:53:29 +0300 Subject: [PATCH] examples/http_server.py: Refactor/simplify for Python 3.5. --- examples/network/http_server.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/network/http_server.py b/examples/network/http_server.py index 7affafcfd6..923b4f9aef 100644 --- a/examples/network/http_server.py +++ b/examples/network/http_server.py @@ -4,10 +4,10 @@ except: import socket -CONTENT = """\ +CONTENT = b"""\ HTTP/1.0 200 OK -Hello #{} from MicroPython! +Hello #%d from MicroPython! """ s = socket.socket() @@ -30,12 +30,13 @@ while True: print("Client socket:", client_s) print("Request:") if 0: - # MicroPython rawsocket module supports file interface directly + # MicroPython socket objects support stream (aka file) interface + # directly. print(client_s.read(4096)) - #print(client_s.readall()) - client_s.write(CONTENT.format(counter)) + client_s.write(CONTENT % counter) else: print(client_s.recv(4096)) - client_s.send(bytes(CONTENT.format(counter), "ascii")) + client_s.send(CONTENT % counter) client_s.close() counter += 1 + print()