aiocoap.transports.udp6 module

This module implements a TransportEndpoint for UDP based on a variation of the asyncio DatagramProtocol.

This implementation strives to be correct and complete behavior while still only using a single socket; that is, to be usable for all kinds of multicast traffic, to support server and client behavior at the same time, and to work correctly even when multiple IPv6 and IPv4 (using V4MAPPED addresses) interfaces are present, and any of the interfaces has multiple addresses.

This requires using a plethorea of standardized but not necessarily widely ported features: AI_V4MAPPED to support IPv4 without resorting to less standardized mechanisms for later options, IPV6_RECVPKTINFO to determine incoming packages’ destination addresses (was it multicast) and to return packages from the same address, IPV6_RECVERR to receive ICMP errors even on sockets that are not connected, IPV6_JOIN_GROUP for multicast membership management, and recvmsg and MSG_ERRQUEUE to obtain the data configured with the above options.

There are, if at all, only little attempts made to fall back to a kind-of-correct or limited-functionality behavior if these options are unavailable, for the resulting code would be hard to maintain (“ifdef hell”) or would cause odd bugs at users (eg. servers that stop working when an additional IPv6 address gets assigned). If the module does not work for you, and the options can not be added easily to your platform, consider using the simple6 module instead.

class aiocoap.transports.udp6.UDP6EndpointAddress(sockaddr, *, pktinfo=None)

Bases: aiocoap.interfaces.EndpointAddress

Remote address type for :cls:`TransportEndpointUDP6`. Remote address is stored in form of a socket address; local address can be roundtripped by opaque pktinfo data.

>>> local = UDP6EndpointAddress(socket.getaddrinfo('127.0.0.1', 5683, type=socket.SOCK_DGRAM, family=socket.AF_INET6, flags=socket.AI_V4MAPPED)[0][-1])
>>> local.is_multicast
False
>>> local.hostinfo
'127.0.0.1'
>>> all_coap_site = UDP6EndpointAddress(socket.getaddrinfo('ff05:0:0:0:0:0:0:fd', 1234, type=socket.SOCK_DGRAM, family=socket.AF_INET6)[0][-1])
>>> all_coap_site.is_multicast
True
>>> all_coap_site.hostinfo
'[ff05::fd]:1234'
>>> all_coap4 = UDP6EndpointAddress(socket.getaddrinfo('224.0.1.187', 5683, type=socket.SOCK_DGRAM, family=socket.AF_INET6, flags=socket.AI_V4MAPPED)[0][-1])
>>> all_coap4.is_multicast
True
hostinfo
uri
is_multicast
is_multicast_locally
class aiocoap.transports.udp6.SockExtendedErr

Bases: aiocoap.transports.udp6._SockExtendedErr

classmethod load(data)
class aiocoap.transports.udp6.TransportEndpointUDP6(ctx: aiocoap.interfaces.MessageManager, log, loop)

Bases: aiocoap.util.asyncio.RecvmsgDatagramProtocol, aiocoap.interfaces.TransportEndpoint

ready = None

Future that gets fullfilled by connection_made (ie. don’t send before this is done; handled by create_..._context

classmethod create_client_transport_endpoint(ctx: aiocoap.interfaces.MessageManager, log, loop, dump_to)
classmethod create_server_transport_endpoint(ctx: aiocoap.interfaces.MessageManager, log, loop, dump_to, bind)
shutdown()
send(message)
determine_remote(request)
connection_made(transport)

Implementation of the DatagramProtocol interface, called by the transport.

datagram_msg_received(data, ancdata, flags, address)

Implementation of the RecvmsgDatagramProtocol interface, called by the transport.

datagram_errqueue_received(data, ancdata, flags, address)
error_received(exc)

Implementation of the DatagramProtocol interface, called by the transport.

connection_lost(exc)