UDP — UDP handle

class pyuv.UDP(loop)
Parameters:loop (Loop) – loop object where this handle runs (accessible through UDP.loop).

The UDP handle provides asynchronous UDP functionality both as a client and server.

bind((ip, port, [flowinfo, [scope_id]]), [flags])
Parameters:
  • ip (string) – IP address to bind to.
  • port (int) – Port number to bind to.
  • flowinfo (int) – Flow info, used only for IPv6. Defaults to 0.
  • scope_id (int) – Scope ID, used only for IPv6. Defaults to 0.
  • flags (int) – Binding flags. Only pyuv.UV_UDP_IPV6ONLY is supported at the moment, which disables dual stack support on IPv6 handles.

Bind to the specified IP address and port. This function needs to be called always, both when acting as a client and as a server. It sets the local IP address and port from which the data will be sent.

open(fd)
Parameters:fd (int) – File descriptor to be opened.

Open the given file descriptor (or SOCKET in Windows) as a UDP handle.

..note::
The file descriptor will be closed when the UDP handle is closed, so if it was tasken from a Python socket object, it will be useless afterwards.
getsockname()

Return tuple containing IP address and port of the local socket. In case of IPv6 sockets, it also returns the flow info and scope ID (a 4 element tuple).

send((ip, port, [flowinfo, [scope_id]]), data, [callback])
Parameters:
  • ip (string) – IP address where data will be sent.
  • port (int) – Port number where data will be sent.
  • flowinfo (int) – Flow info, used only for IPv6. Defaults to 0.
  • scope_id (int) – Scope ID, used only for IPv6. Defaults to 0.
  • data (object) – Data to be sent over the UDP connection. It can be either a string or any iterable containing strings.
  • callback (callable) – Callback to be called after the send operation has been performed.

Send data over the UDP connection.

Callback signature: callback(udp_handle, error).

sendlines((ip, port, [flowinfo, [scope_id]]), seq, [callback])
Parameters:
  • ip (string) – IP address where data will be sent.
  • port (int) – Port number where data will be sent.
  • flowinfo (int) – Flow info, used only for IPv6. Defaults to 0.
  • scope_id (int) – Scope ID, used only for IPv6. Defaults to 0.
  • seq (object) – Data to be written on the UDP connection. It can be any iterable object and the same logic is applied for the contained elements as in the send method.
  • callback (callable) – Callback to be called after the send operation has been performed.

Send data over the UDP connection.

Callback signature: callback(udp_handle, error).

start_recv(callback)
Parameters:callback (callable) – Callback to be called when data is received on the bount IP address and port.

Start receiving data on the bound IP address and port.

Callback signature: callback(udp_handle, (ip, port), flags, data, error). The flags attribute can only contain pyuv.UV_UDP_PARTIAL, in case the UDP packet was truncated.

stop_recv()

Stop receiving data.

set_membership(multicast_address, membership[, interface])
Parameters:
  • multicast_address (string) – Multicast group to join / leave.
  • membership (int) – Flag indicating if the operation is join or leave. Flags: pyuv.UV_JOIN_GROUP and pyuv.UV_LEAVE_GROUP.
  • interface (string) – Local interface address to use to join or leave the specified multicast group.

Join or leave a multicast group.

set_multicast_ttl(ttl)
Parameters:ttl (int) – TTL value to be set.

Set the multicast Time To Live (TTL).

set_multicast_loop(enable)
Parameters:enable (boolean) – On /off.

Set IP multicast loop flag. Makes multicast packets loop back to local sockets.

set_broadcast(enable)
Parameters:enable (boolean) – On /off.

Set broadcast on or off.

set_ttl(ttl)
Parameters:ttl (int) – TTL value to be set.

Set the Time To Live (TTL).

Previous topic

TCP — TCP handle

Next topic

Pipe — Named pipe handle

This Page