Code: Select all
import uasyncio as asyncio
async def handle_echo(reader, writer):
# while (True):
data = await reader.read(128)
if (data):
message = data.decode()
addr = writer.get_extra_info('peername')
print("Received %r from %r" % (message, addr))
print(type(data))
message = ("HTTP/1.0 200 OK\r\n\r\nHello World \r\n")
writer.write(message)
await writer.drain()
else:
print("Close the client socket")
writer.close()
await writer.wait_closed()
loop = asyncio.get_event_loop()
coro = asyncio.start_server(handle_echo, '0.0.0.0', 80)
server = loop.run_until_complete(coro)
try:
loop.run_forever()
except KeyboardInterrupt:
pass
# Close the server
server.close()
loop.run_until_complete(server.wait_closed())
loop.close()
But, the "Hello World" message does not show up on the browser. But, when I interrupt the script by Ctrl+C and soft reset the ESP8266 board, voila message appears on the browser as expected. What am I missing?Received 'GET / HTTP/1.1\r\nHost: 192.168.4.1\r\nUpgrade-Insecure-Requests: 1\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*' from ('192.168.4.2', 50805)
<class 'bytes'>