asyncio.AbstractEventLoop.create_datagram_endpoint()

coroutine AbstractEventLoop.create_datagram_endpoint(protocol_factory, local_addr=None, remote_addr=None, *, family=0, proto=0, flags=0, reuse_address=None, reuse_port=None, allow_broadcast=None, sock=None)

Create datagram connection: socket family AF_INET or AF_INET6 depending on host (or family if specified), socket type SOCK_DGRAM. protocol_factory must be a callable returning a protocol instance.

This method is a coroutine which will try to establish the connection in the background. When successful, the coroutine returns a (transport, protocol) pair.

Options changing how the connection is created:

  • local_addr, if given, is a (local_host, local_port) tuple used to bind the socket to locally. The local_host and local_port are looked up using getaddrinfo().
  • remote_addr, if given, is a (remote_host, remote_port) tuple used to connect the socket to a remote address. The remote_host and remote_port are looked up using getaddrinfo().
  • family, proto, flags are the optional address family, protocol and flags to be passed through to getaddrinfo() for host resolution. If given, these should all be integers from the corresponding socket module constants.
  • reuse_address tells the kernel to reuse a local socket in TIME_WAIT state, without waiting for its natural timeout to expire. If not specified will automatically be set to True on UNIX.
  • reuse_port tells the kernel to allow this endpoint to be bound to the same port as other existing endpoints are bound to, so long as they all set this flag when being created. This option is not supported on Windows and some UNIX’s. If the SO_REUSEPORT constant is not defined then this capability is unsupported.
  • allow_broadcast tells the kernel to allow this endpoint to send messages to the broadcast address.
  • sock can optionally be specified in order to use a preexisting, already connected, socket.socket object to be used by the transport. If specified, local_addr and remote_addr should be omitted (must be None).

On Windows with ProactorEventLoop, this method is not supported.

See UDP echo client protocol and UDP echo server protocol examples.

doc_python
2016-10-07 17:26:28
Comments
Leave a Comment

Please login to continue.