A better API for asynchronous UDP
Project description
AioUDP
A better API for asynchronous UDP
A websockets-like API for UDP
Here's an example echo server:
import asyncio
import signal
import aioudp
async def main():
async def handler(connection):
async for message in connection:
await connection.send(message)
# Optional. This is for properly exiting the server when Ctrl-C is pressed
# or when the process is killed/terminated
loop = asyncio.get_running_loop()
stop = loop.create_future()
loop.add_signal_handler(signal.SIGTERM, stop.set_result, None)
loop.add_signal_handler(signal.SIGINT, stop.set_result, None)
# Serve the server
async with aioudp.serve("localhost", 9999, handler):
await stop # Serve forever
if __name__ == '__main__':
asyncio.run(main())
And a client to connect to the server:
import asyncio
import aioudp
async def main():
async with aioudp.connect("localhost", 9999) as connection:
await connection.send(b"Hello world!")
assert await connection.recv() == b"Hello world!"
if __name__ == '__main__':
asyncio.run(main())
NOTE: This library provides no other abstractions over the existing UDP interface in asyncio
other than the async
/await
-based API. This means there is no implicit protocol handled in this library. You must write your own.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aioudp-0.1.1.tar.gz
(17.2 kB
view hashes)
Built Distribution
aioudp-0.1.1-py3-none-any.whl
(18.1 kB
view hashes)