Send a DNS message to the specified UDP socket. *sock*, a ``dns.asyncbackend.DatagramSocket``. *what*, a ``bytes`` or ``dns.message.Message``, the message to send. *destination*, a destination tuple appropriate for the address family of the socket, specifying where to send the que
(
sock: dns.asyncbackend.DatagramSocket,
what: dns.message.Message | bytes,
destination: Any,
expiration: float | None = None,
)
| 89 | |
| 90 | |
| 91 | async def send_udp( |
| 92 | sock: dns.asyncbackend.DatagramSocket, |
| 93 | what: dns.message.Message | bytes, |
| 94 | destination: Any, |
| 95 | expiration: float | None = None, |
| 96 | ) -> Tuple[int, float]: |
| 97 | """Send a DNS message to the specified UDP socket. |
| 98 | |
| 99 | *sock*, a ``dns.asyncbackend.DatagramSocket``. |
| 100 | |
| 101 | *what*, a ``bytes`` or ``dns.message.Message``, the message to send. |
| 102 | |
| 103 | *destination*, a destination tuple appropriate for the address family |
| 104 | of the socket, specifying where to send the query. |
| 105 | |
| 106 | *expiration*, a ``float`` or ``None``, the absolute time at which |
| 107 | a timeout exception should be raised. If ``None``, no timeout will |
| 108 | occur. The expiration value is meaningless for the asyncio backend, as |
| 109 | asyncio's transport sendto() never blocks. |
| 110 | |
| 111 | Returns an ``(int, float)`` tuple of bytes sent and the sent time. |
| 112 | """ |
| 113 | |
| 114 | if isinstance(what, dns.message.Message): |
| 115 | what = what.to_wire() |
| 116 | sent_time = time.time() |
| 117 | n = await sock.sendto(what, destination, _timeout(expiration, sent_time)) |
| 118 | return (n, sent_time) |
| 119 | |
| 120 | |
| 121 | async def receive_udp( |