Skip to content

Commit aa3fb7b

Browse files
committed
examples/http_server.py: Refactor/simplify for Python 3.5.
1 parent fd2b71f commit aa3fb7b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

examples/network/http_server.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import socket
55

66

7-
CONTENT = """\
7+
CONTENT = b"""\
88
HTTP/1.0 200 OK
99
10-
Hello #{} from MicroPython!
10+
Hello #%d from MicroPython!
1111
"""
1212

1313
s = socket.socket()
@@ -30,12 +30,13 @@
3030
print("Client socket:", client_s)
3131
print("Request:")
3232
if 0:
33-
# MicroPython rawsocket module supports file interface directly
33+
# MicroPython socket objects support stream (aka file) interface
34+
# directly.
3435
print(client_s.read(4096))
35-
#print(client_s.readall())
36-
client_s.write(CONTENT.format(counter))
36+
client_s.write(CONTENT % counter)
3737
else:
3838
print(client_s.recv(4096))
39-
client_s.send(bytes(CONTENT.format(counter), "ascii"))
39+
client_s.send(CONTENT % counter)
4040
client_s.close()
4141
counter += 1
42+
print()

0 commit comments

Comments
 (0)