Frequently Asked Questions

Common questions you may have

Why do the messages need to be in bytes?

Because it makes sense. UDP is unreliable but fast, making it a good choice for streaming audio/video.

If you’re trying to send strings, you’re probably misusing this library. I recommend a good TCP (to be precise, WebSockets) library called websockets. It has a similar API to this library. In fact, this library’s API was inspired by the websockets library.

Otherwise, if you know what you’re doing, just .encode your strings.

Why is my code hanging?

You may be using recv when the server didn’t send anything to the client or an exception happened in the server. If this is the case, you should add a timeout.

How can I first send a message to the connected client?

This is currently not possible with this library, as I could not figure out how to do it with the normal Python API in the first place. However, if this is possible in the normal Python asyncio UDP API, this is a limitation of the library and we welcome you file an issue <https://github.com/ThatXliner/aioudp>.

How can I add a timeout?

This is not specific to AioUDP, but rather a general asyncio-related question.

You should use asyncio.wait_for

Example:

try:
    await asyncio.wait_for(func(), timeout=0.01)
except asyncio.TimeoutError:
    print("timeout!")

Where func is the function you want to add a timeout to.