Files
godot-docs-l10n/classes/es/class_upnp.rst

594 lines
30 KiB
ReStructuredText

:github_url: hide
.. _class_UPNP:
UPNP
====
**Hereda:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
Universal Plug and Play (UPnP) functions for network device discovery, querying and port forwarding.
.. rst-class:: classref-introduction-group
Descripción
----------------------
This class can be used to discover compatible :ref:`UPNPDevice<class_UPNPDevice>`\ s on the local network and execute commands on them, like managing port mappings (for port forwarding/NAT traversal) and querying the local and remote network IP address. Note that methods on this class are synchronous and block the calling thread.
To forward a specific port (here ``7777``, note both :ref:`discover()<class_UPNP_method_discover>` and :ref:`add_port_mapping()<class_UPNP_method_add_port_mapping>` can return errors that should be checked):
::
var upnp = UPNP.new()
upnp.discover()
upnp.add_port_mapping(7777)
To close a specific port (e.g. after you have finished using it):
::
upnp.delete_port_mapping(port)
\ **Note:** UPnP discovery blocks the current thread. To perform discovery without blocking the main thread, use :ref:`Thread<class_Thread>`\ s like this:
::
# Emitted when UPnP port mapping setup is completed (regardless of success or failure).
signal upnp_completed(error)
# Replace this with your own server port number between 1024 and 65535.
const SERVER_PORT = 3928
var thread = null
func _upnp_setup(server_port):
# UPNP queries take some time.
var upnp = UPNP.new()
var err = upnp.discover()
if err != OK:
push_error(str(err))
upnp_completed.emit(err)
return
if upnp.get_gateway() and upnp.get_gateway().is_valid_gateway():
upnp.add_port_mapping(server_port, server_port, ProjectSettings.get_setting("application/config/name"), "UDP")
upnp.add_port_mapping(server_port, server_port, ProjectSettings.get_setting("application/config/name"), "TCP")
upnp_completed.emit(OK)
func _ready():
thread = Thread.new()
thread.start(_upnp_setup.bind(SERVER_PORT))
func _exit_tree():
# Wait for thread finish here to handle game exit while the thread is running.
thread.wait_to_finish()
\ **Terminology:** In the context of UPnP networking, "gateway" (or "internet gateway device", short IGD) refers to network devices that allow computers in the local network to access the internet ("wide area network", WAN). These gateways are often also called "routers".
\ **Pitfalls:**\
- As explained above, these calls are blocking and shouldn't be run on the main thread, especially as they can block for multiple seconds at a time. Use threading!
- Networking is physical and messy. Packets get lost in transit or get filtered, addresses, free ports and assigned mappings change, and devices may leave or join the network at any time. Be mindful of this, be diligent when checking and handling errors, and handle these gracefully if you can: add clear error UI, timeouts and re-try handling.
- Port mappings may change (and be removed) at any time, and the remote/external IP address of the gateway can change likewise. You should consider re-querying the external IP and try to update/refresh the port mapping periodically (for example, every 5 minutes and on networking failures).
- Not all devices support UPnP, and some users disable UPnP support. You need to handle this (e.g. documenting and requiring the user to manually forward ports, or adding alternative methods of NAT traversal, like a relay/mirror server, or NAT hole punching, STUN/TURN, etc.).
- Consider what happens on mapping conflicts. Maybe multiple users on the same network would like to play your game at the same time, or maybe another application uses the same port. Make the port configurable, and optimally choose a port automatically (re-trying with a different port on failure).
\ **Further reading:** If you want to know more about UPnP (and the Internet Gateway Device (IGD) and Port Control Protocol (PCP) specifically), `Wikipedia <https://en.wikipedia.org/wiki/Universal_Plug_and_Play>`__ is a good first stop, the specification can be found at the `Open Connectivity Foundation <https://openconnectivity.org/developer/specifications/upnp-resources/upnp/>`__ and Godot's implementation is based on the `MiniUPnP client <https://github.com/miniupnp/miniupnp>`__.
.. rst-class:: classref-reftable-group
Propiedades
----------------------
.. table::
:widths: auto
+-----------------------------+-------------------------------------------------------------------------+-----------+
| :ref:`bool<class_bool>` | :ref:`discover_ipv6<class_UPNP_property_discover_ipv6>` | ``false`` |
+-----------------------------+-------------------------------------------------------------------------+-----------+
| :ref:`int<class_int>` | :ref:`discover_local_port<class_UPNP_property_discover_local_port>` | ``0`` |
+-----------------------------+-------------------------------------------------------------------------+-----------+
| :ref:`String<class_String>` | :ref:`discover_multicast_if<class_UPNP_property_discover_multicast_if>` | ``""`` |
+-----------------------------+-------------------------------------------------------------------------+-----------+
.. rst-class:: classref-reftable-group
Métodos
--------------
.. table::
:widths: auto
+-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`add_device<class_UPNP_method_add_device>`\ (\ device\: :ref:`UPNPDevice<class_UPNPDevice>`\ ) |
+-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`add_port_mapping<class_UPNP_method_add_port_mapping>`\ (\ port\: :ref:`int<class_int>`, port_internal\: :ref:`int<class_int>` = 0, desc\: :ref:`String<class_String>` = "", proto\: :ref:`String<class_String>` = "UDP", duration\: :ref:`int<class_int>` = 0\ ) |const| |
+-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`clear_devices<class_UPNP_method_clear_devices>`\ (\ ) |
+-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`delete_port_mapping<class_UPNP_method_delete_port_mapping>`\ (\ port\: :ref:`int<class_int>`, proto\: :ref:`String<class_String>` = "UDP"\ ) |const| |
+-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`discover<class_UPNP_method_discover>`\ (\ timeout\: :ref:`int<class_int>` = 2000, ttl\: :ref:`int<class_int>` = 2, device_filter\: :ref:`String<class_String>` = "InternetGatewayDevice"\ ) |
+-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`UPNPDevice<class_UPNPDevice>` | :ref:`get_device<class_UPNP_method_get_device>`\ (\ index\: :ref:`int<class_int>`\ ) |const| |
+-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`get_device_count<class_UPNP_method_get_device_count>`\ (\ ) |const| |
+-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`UPNPDevice<class_UPNPDevice>` | :ref:`get_gateway<class_UPNP_method_get_gateway>`\ (\ ) |const| |
+-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`String<class_String>` | :ref:`query_external_address<class_UPNP_method_query_external_address>`\ (\ ) |const| |
+-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`remove_device<class_UPNP_method_remove_device>`\ (\ index\: :ref:`int<class_int>`\ ) |
+-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`set_device<class_UPNP_method_set_device>`\ (\ index\: :ref:`int<class_int>`, device\: :ref:`UPNPDevice<class_UPNPDevice>`\ ) |
+-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Enumeraciones
--------------------------
.. _enum_UPNP_UPNPResult:
.. rst-class:: classref-enumeration
enum **UPNPResult**: :ref:`🔗<enum_UPNP_UPNPResult>`
.. _class_UPNP_constant_UPNP_RESULT_SUCCESS:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_SUCCESS** = ``0``
El comando o descubrimiento de la UPNP fue exitoso.
.. _class_UPNP_constant_UPNP_RESULT_NOT_AUTHORIZED:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_NOT_AUTHORIZED** = ``1``
No está autorizado a usar el comando en el :ref:`UPNPDevice<class_UPNPDevice>`. Puede ser devuelto cuando el usuario deshabilite el UPNP en su router.
.. _class_UPNP_constant_UPNP_RESULT_PORT_MAPPING_NOT_FOUND:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_PORT_MAPPING_NOT_FOUND** = ``2``
No se encontró ningún mapeo de puerto para la combinación de protocolos del :ref:`UPNPDevice<class_UPNPDevice>` dado.
.. _class_UPNP_constant_UPNP_RESULT_INCONSISTENT_PARAMETERS:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_INCONSISTENT_PARAMETERS** = ``3``
Parámetros inconsistentes.
.. _class_UPNP_constant_UPNP_RESULT_NO_SUCH_ENTRY_IN_ARRAY:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_NO_SUCH_ENTRY_IN_ARRAY** = ``4``
No existe tal entrada en el array. Puede ser devuelto si una combinación dada de puerto y protocolo no se encuentra en un :ref:`UPNPDevice<class_UPNPDevice>`.
.. _class_UPNP_constant_UPNP_RESULT_ACTION_FAILED:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_ACTION_FAILED** = ``5``
La acción falló.
.. _class_UPNP_constant_UPNP_RESULT_SRC_IP_WILDCARD_NOT_PERMITTED:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_SRC_IP_WILDCARD_NOT_PERMITTED** = ``6``
El :ref:`UPNPDevice<class_UPNPDevice>` no permite valores comodín para la dirección IP de origen.
.. _class_UPNP_constant_UPNP_RESULT_EXT_PORT_WILDCARD_NOT_PERMITTED:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_EXT_PORT_WILDCARD_NOT_PERMITTED** = ``7``
El :ref:`UPNPDevice<class_UPNPDevice>` no permite valores comodín para el puerto externo.
.. _class_UPNP_constant_UPNP_RESULT_INT_PORT_WILDCARD_NOT_PERMITTED:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_INT_PORT_WILDCARD_NOT_PERMITTED** = ``8``
El :ref:`UPNPDevice<class_UPNPDevice>` no permite valores comodín para el puerto interno.
.. _class_UPNP_constant_UPNP_RESULT_REMOTE_HOST_MUST_BE_WILDCARD:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_REMOTE_HOST_MUST_BE_WILDCARD** = ``9``
El valor del host remoto debe ser un comodín.
.. _class_UPNP_constant_UPNP_RESULT_EXT_PORT_MUST_BE_WILDCARD:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_EXT_PORT_MUST_BE_WILDCARD** = ``10``
El valor del puerto externo debe ser un comodín.
.. _class_UPNP_constant_UPNP_RESULT_NO_PORT_MAPS_AVAILABLE:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_NO_PORT_MAPS_AVAILABLE** = ``11``
No hay mapas de puertos disponibles. También puede ser devuelto si la funcionalidad de mapas de puertos no está disponible.
.. _class_UPNP_constant_UPNP_RESULT_CONFLICT_WITH_OTHER_MECHANISM:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_CONFLICT_WITH_OTHER_MECHANISM** = ``12``
Conflicto con otro mecanismo. Puede ser devuelto en lugar de :ref:`UPNP_RESULT_CONFLICT_WITH_OTHER_MAPPING<class_UPNP_constant_UPNP_RESULT_CONFLICT_WITH_OTHER_MAPPING>` si un mapeo de puertos entra en conflicto con uno existente.
.. _class_UPNP_constant_UPNP_RESULT_CONFLICT_WITH_OTHER_MAPPING:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_CONFLICT_WITH_OTHER_MAPPING** = ``13``
Conflicto con una mapeo de puertos existente.
.. _class_UPNP_constant_UPNP_RESULT_SAME_PORT_VALUES_REQUIRED:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_SAME_PORT_VALUES_REQUIRED** = ``14``
Los valores de los puertos externos e internos deben ser los mismos.
.. _class_UPNP_constant_UPNP_RESULT_ONLY_PERMANENT_LEASE_SUPPORTED:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_ONLY_PERMANENT_LEASE_SUPPORTED** = ``15``
Sólo se admiten los arrendamientos permanentes. No utilices el parámetro ``duration`` cuando añada mapeos de puertos.
.. _class_UPNP_constant_UPNP_RESULT_INVALID_GATEWAY:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_INVALID_GATEWAY** = ``16``
Gateway invalida.
.. _class_UPNP_constant_UPNP_RESULT_INVALID_PORT:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_INVALID_PORT** = ``17``
Puerto inválido.
.. _class_UPNP_constant_UPNP_RESULT_INVALID_PROTOCOL:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_INVALID_PROTOCOL** = ``18``
Protocolo inválido.
.. _class_UPNP_constant_UPNP_RESULT_INVALID_DURATION:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_INVALID_DURATION** = ``19``
Duración inválida.
.. _class_UPNP_constant_UPNP_RESULT_INVALID_ARGS:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_INVALID_ARGS** = ``20``
Argumentos inválidos.
.. _class_UPNP_constant_UPNP_RESULT_INVALID_RESPONSE:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_INVALID_RESPONSE** = ``21``
Respuesta inválida.
.. _class_UPNP_constant_UPNP_RESULT_INVALID_PARAM:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_INVALID_PARAM** = ``22``
Parámetro inválido.
.. _class_UPNP_constant_UPNP_RESULT_HTTP_ERROR:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_HTTP_ERROR** = ``23``
Error HTTP.
.. _class_UPNP_constant_UPNP_RESULT_SOCKET_ERROR:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_SOCKET_ERROR** = ``24``
Error de socket.
.. _class_UPNP_constant_UPNP_RESULT_MEM_ALLOC_ERROR:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_MEM_ALLOC_ERROR** = ``25``
Error en la asignación de la memoria.
.. _class_UPNP_constant_UPNP_RESULT_NO_GATEWAY:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_NO_GATEWAY** = ``26``
No hay ninguna gateway disponible. Puede que tengas que llamar a :ref:`discover()<class_UPNP_method_discover>` primero, o el descubrimiento no detectó ningúna IGD (InternetGatewayDevices) válida.
.. _class_UPNP_constant_UPNP_RESULT_NO_DEVICES:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_NO_DEVICES** = ``27``
No hay dispositivos disponibles. Puede que tengas que llamar a :ref:`discover()<class_UPNP_method_discover>` primero, o el descubrimiento no detectó ninguna :ref:`UPNPDevice<class_UPNPDevice>` válida.
.. _class_UPNP_constant_UPNP_RESULT_UNKNOWN_ERROR:
.. rst-class:: classref-enumeration-constant
:ref:`UPNPResult<enum_UPNP_UPNPResult>` **UPNP_RESULT_UNKNOWN_ERROR** = ``28``
Error desconocido.
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Descripciones de Propiedades
--------------------------------------------------------
.. _class_UPNP_property_discover_ipv6:
.. rst-class:: classref-property
:ref:`bool<class_bool>` **discover_ipv6** = ``false`` :ref:`🔗<class_UPNP_property_discover_ipv6>`
.. rst-class:: classref-property-setget
- |void| **set_discover_ipv6**\ (\ value\: :ref:`bool<class_bool>`\ )
- :ref:`bool<class_bool>` **is_discover_ipv6**\ (\ )
Si es ``true``, IPv6 se utiliza para el descubrimiento de :ref:`UPNPDevice<class_UPNPDevice>`.
.. rst-class:: classref-item-separator
----
.. _class_UPNP_property_discover_local_port:
.. rst-class:: classref-property
:ref:`int<class_int>` **discover_local_port** = ``0`` :ref:`🔗<class_UPNP_property_discover_local_port>`
.. rst-class:: classref-property-setget
- |void| **set_discover_local_port**\ (\ value\: :ref:`int<class_int>`\ )
- :ref:`int<class_int>` **get_discover_local_port**\ (\ )
Si ``0``, el puerto local a utilizar para el descubrimiento es elegido automáticamente por el sistema. Si ``1``, el descubrimiento se hará desde el puerto de origen 1900 (el mismo que el puerto de destino). De lo contrario, el valor se utilizará como el puerto.
.. rst-class:: classref-item-separator
----
.. _class_UPNP_property_discover_multicast_if:
.. rst-class:: classref-property
:ref:`String<class_String>` **discover_multicast_if** = ``""`` :ref:`🔗<class_UPNP_property_discover_multicast_if>`
.. rst-class:: classref-property-setget
- |void| **set_discover_multicast_if**\ (\ value\: :ref:`String<class_String>`\ )
- :ref:`String<class_String>` **get_discover_multicast_if**\ (\ )
Interfaz de multidifusión para usar para el descubrimiento. Utiliza la interfaz de multidifusión predeterminada si está vacía.
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Descripciones de Métodos
------------------------------------------------
.. _class_UPNP_method_add_device:
.. rst-class:: classref-method
|void| **add_device**\ (\ device\: :ref:`UPNPDevice<class_UPNPDevice>`\ ) :ref:`🔗<class_UPNP_method_add_device>`
Añade el :ref:`UPNPDevice<class_UPNPDevice>` dado a la lista de dispositivos descubiertos.
.. rst-class:: classref-item-separator
----
.. _class_UPNP_method_add_port_mapping:
.. rst-class:: classref-method
:ref:`int<class_int>` **add_port_mapping**\ (\ port\: :ref:`int<class_int>`, port_internal\: :ref:`int<class_int>` = 0, desc\: :ref:`String<class_String>` = "", proto\: :ref:`String<class_String>` = "UDP", duration\: :ref:`int<class_int>` = 0\ ) |const| :ref:`🔗<class_UPNP_method_add_port_mapping>`
Adds a mapping to forward the external ``port`` (between 1 and 65535, although recommended to use port 1024 or above) on the default gateway (see :ref:`get_gateway()<class_UPNP_method_get_gateway>`) to the ``port_internal`` on the local machine for the given protocol ``proto`` (either ``"TCP"`` or ``"UDP"``, with UDP being the default). If a port mapping for the given port and protocol combination already exists on that gateway device, this method tries to overwrite it. If that is not desired, you can retrieve the gateway manually with :ref:`get_gateway()<class_UPNP_method_get_gateway>` and call :ref:`add_port_mapping()<class_UPNP_method_add_port_mapping>` on it, if any. Note that forwarding a well-known port (below 1024) with UPnP may fail depending on the device.
Depending on the gateway device, if a mapping for that port already exists, it will either be updated or it will refuse this command due to that conflict, especially if the existing mapping for that port wasn't created via UPnP or points to a different network address (or device) than this one.
If ``port_internal`` is ``0`` (the default), the same port number is used for both the external and the internal port (the ``port`` value).
The description (``desc``) is shown in some routers management UIs and can be used to point out which application added the mapping.
The mapping's lease ``duration`` can be limited by specifying a duration in seconds. The default of ``0`` means no duration, i.e. a permanent lease and notably some devices only support these permanent leases. Note that whether permanent or not, this is only a request and the gateway may still decide at any point to remove the mapping (which usually happens on a reboot of the gateway, when its external IP address changes, or on some models when it detects a port mapping has become inactive, i.e. had no traffic for multiple minutes). If not ``0`` (permanent), the allowed range according to spec is between ``120`` (2 minutes) and ``86400`` seconds (24 hours).
See :ref:`UPNPResult<enum_UPNP_UPNPResult>` for possible return values.
.. rst-class:: classref-item-separator
----
.. _class_UPNP_method_clear_devices:
.. rst-class:: classref-method
|void| **clear_devices**\ (\ ) :ref:`🔗<class_UPNP_method_clear_devices>`
Borra la lista de dispositivos descubiertos.
.. rst-class:: classref-item-separator
----
.. _class_UPNP_method_delete_port_mapping:
.. rst-class:: classref-method
:ref:`int<class_int>` **delete_port_mapping**\ (\ port\: :ref:`int<class_int>`, proto\: :ref:`String<class_String>` = "UDP"\ ) |const| :ref:`🔗<class_UPNP_method_delete_port_mapping>`
Elimina la asignación de puertos para la combinación de puerto y protocolo dada en la puerta de enlace predeterminada (ver :ref:`get_gateway()<class_UPNP_method_get_gateway>`) si existe. ``port`` debe ser un puerto válido entre 1 y 65535, ``proto`` puede ser ``"TCP"`` o ``"UDP"``. Puede ser rechazado para asignaciones que apunten a direcciones que no sean esta, para puertos conocidos (por debajo de 1024), o para asignaciones no añadidas a través de UPnP. Véase :ref:`UPNPResult<enum_UPNP_UPNPResult>` para ver los posibles valores de retorno.
.. rst-class:: classref-item-separator
----
.. _class_UPNP_method_discover:
.. rst-class:: classref-method
:ref:`int<class_int>` **discover**\ (\ timeout\: :ref:`int<class_int>` = 2000, ttl\: :ref:`int<class_int>` = 2, device_filter\: :ref:`String<class_String>` = "InternetGatewayDevice"\ ) :ref:`🔗<class_UPNP_method_discover>`
Descubre los :ref:`UPNPDevice<class_UPNPDevice>`\ s locales. Borra la lista de dispositivos descubiertos anteriormente.
Filtra los dispositivos de tipo IGD (InternetGatewayDevice) por defecto, ya que estos gestionan el reenvío de puertos. ``timeout`` es el tiempo de espera de las respuestas en milisegundos. ``ttl`` es el tiempo de vida; solo toca esto si sabes lo que estás haciendo.
Véase :ref:`UPNPResult<enum_UPNP_UPNPResult>` para ver los posibles valores de retorno.
.. rst-class:: classref-item-separator
----
.. _class_UPNP_method_get_device:
.. rst-class:: classref-method
:ref:`UPNPDevice<class_UPNPDevice>` **get_device**\ (\ index\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_UPNP_method_get_device>`
Devuelve el :ref:`UPNPDevice<class_UPNPDevice>` en el ``index`` dado.
.. rst-class:: classref-item-separator
----
.. _class_UPNP_method_get_device_count:
.. rst-class:: classref-method
:ref:`int<class_int>` **get_device_count**\ (\ ) |const| :ref:`🔗<class_UPNP_method_get_device_count>`
Devuelve el número de :ref:`UPNPDevice<class_UPNPDevice>` descubiertos.
.. rst-class:: classref-item-separator
----
.. _class_UPNP_method_get_gateway:
.. rst-class:: classref-method
:ref:`UPNPDevice<class_UPNPDevice>` **get_gateway**\ (\ ) |const| :ref:`🔗<class_UPNP_method_get_gateway>`
Devuelve la puerta de enlace por defecto. Es el primer dispositivo descubierto :ref:`UPNPDevice<class_UPNPDevice>` que también es un IGD (InternetGatewayDevice) válido.
.. rst-class:: classref-item-separator
----
.. _class_UPNP_method_query_external_address:
.. rst-class:: classref-method
:ref:`String<class_String>` **query_external_address**\ (\ ) |const| :ref:`🔗<class_UPNP_method_query_external_address>`
Devuelve la dirección :ref:`IP<class_IP>` externa de la pasarela por defecto (véase :ref:`get_gateway()<class_UPNP_method_get_gateway>`) como string. Devuelve una string vacía en caso de error.
.. rst-class:: classref-item-separator
----
.. _class_UPNP_method_remove_device:
.. rst-class:: classref-method
|void| **remove_device**\ (\ index\: :ref:`int<class_int>`\ ) :ref:`🔗<class_UPNP_method_remove_device>`
Elimina el dispositivo en ``index`` de la lista de dispositivos descubiertos.
.. rst-class:: classref-item-separator
----
.. _class_UPNP_method_set_device:
.. rst-class:: classref-method
|void| **set_device**\ (\ index\: :ref:`int<class_int>`, device\: :ref:`UPNPDevice<class_UPNPDevice>`\ ) :ref:`🔗<class_UPNP_method_set_device>`
Establece el dispositivo en ``index`` de la lista de dispositivos descubiertos a ``device``.
.. |virtual| replace:: :abbr:`virtual (Normalmente, este método debería ser sobreescrito por el usuario para que tenga algún efecto.)`
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
.. |const| replace:: :abbr:`const (Este método no tiene efectos secundarios. No modifica ninguna de las variables miembro de la instancia.)`
.. |vararg| replace:: :abbr:`vararg (Este método permite agregar cualquier número de argumentos después de los descritos aquí.)`
.. |constructor| replace:: :abbr:`constructor (Este método se utiliza para construir un tipo.)`
.. |static| replace:: :abbr:`static (Este método no necesita una instancia para ser llamado, por lo que puede llamarse directamente utilizando el nombre de la clase.)`
.. |operator| replace:: :abbr:`operator (Este método describe un operador válido para usar con este tipo como operando izquierdo.)`
.. |bitfield| replace:: :abbr:`BitField (Este valor es un entero compuesto como una máscara de bits de las siguientes banderas.)`
.. |void| replace:: :abbr:`void (Sin valor de retorno.)`