Commit a8bd9f45 authored by Alan Marchiori's avatar Alan Marchiori

comments

parent 63e95db6
......@@ -54,7 +54,7 @@ def main(addr, port):
#while True:
if True:
#data, addr = skt.recvfrom(1024) # blocking
data = clientsocket.recv(1024) # blocking, note not recvfrom!
data = clientsocket.recv(1024) # blocking, note *not* recvfrom!
if data:
handle_req(clientsocket,
data,
......
......@@ -2,7 +2,7 @@
Asyncio udp echo/caps server
Alan Marchiori 2019
May be different in python >3.6, requires python >3.5
May be different in python >3.6, requires python >=3.5
"""
import logging
import asyncio # note not socket or socketserver!
......@@ -28,6 +28,10 @@ class MyUdpProtocol:
async def handle_response(self, data, addr):
"simulate a long running response method"
# log rx.
log.info("{} -> {}: {}".format(
addr, self.server_address, data))
# processing delay
await asyncio.sleep(3)
......@@ -46,10 +50,8 @@ class MyUdpProtocol:
a long running task to handle the request.
"""
# log rx.
log.info("{} -> {}: {}".format(
addr, self.server_address, data))
# create and schedule the task defined by the handle_response coroutine
self.loop.create_task(self.handle_response(data, addr))
if __name__ == "__main__":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment