UPNP

UPNP network functions.

Provides UPNP functionality to discover UPNPDevices on the local network and execute commands on them, like managing port mappings (port forwarding) 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:

More...

Members

Aliases

BaseClasses
alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses)
Undocumented in source.

Enums

Constants
enum Constants
UPNPResult
enum UPNPResult

Functions

addDevice
void addDevice(UPNPDevice device)

Adds the given UPNPDevice to the list of discovered devices.

addPortMapping
long addPortMapping(long port, long port_internal, String desc, String proto, long duration)

Adds a mapping to forward the external port (between 1 and 65535) on the default gateway (see getGateway) to the internal_port 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 getGateway and call addPortMapping on it, if any. If internal_port 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 router 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). However, some routers are incompatible with one or both of these, so use with caution and add fallback logic in case of errors to retry without them if in doubt. See upnpresult for possible return values.

clearDevices
void clearDevices()

Clears the list of discovered devices.

deletePortMapping
long deletePortMapping(long port, String proto)

Deletes the port mapping for the given port and protocol combination on the default gateway (see getGateway) if one exists. port must be a valid port between 1 and 65535, proto can be either TCP or UDP. See upnpresult for possible return values.

discover
long discover(long timeout, long ttl, String device_filter)

Discovers local UPNPDevices. Clears the list of previously discovered devices. Filters for IGD (InternetGatewayDevice) type devices by default, as those manage port forwarding. timeout is the time to wait for responses in milliseconds. ttl is the time-to-live; only touch this if you know what you're doing. See upnpresult for possible return values.

getDevice
Ref!UPNPDevice getDevice(long index)

Returns the UPNPDevice at the given index.

getDeviceCount
long getDeviceCount()

Returns the number of discovered UPNPDevices.

getDiscoverLocalPort
long getDiscoverLocalPort()
getDiscoverMulticastIf
String getDiscoverMulticastIf()
getGateway
Ref!UPNPDevice getGateway()

Returns the default gateway. That is the first discovered UPNPDevice that is also a valid IGD (InternetGatewayDevice).

isDiscoverIpv6
bool isDiscoverIpv6()
opAssign
typeof(null) opAssign(typeof(null) n)
opEquals
bool opEquals(UPNP other)
opEquals
bool opEquals(typeof(null) n)
queryExternalAddress
String queryExternalAddress()

Returns the external IP address of the default gateway (see getGateway) as string. Returns an empty string on error.

removeDevice
void removeDevice(long index)

Removes the device at index from the list of discovered devices.

setDevice
void setDevice(long index, UPNPDevice device)

Sets the device at index from the list of discovered devices to device.

setDiscoverIpv6
void setDiscoverIpv6(bool ipv6)
setDiscoverLocalPort
void setDiscoverLocalPort(long port)
setDiscoverMulticastIf
void setDiscoverMulticastIf(String m_if)
toHash
size_t toHash()

Mixins

__anonymous
mixin baseCasts
Undocumented in source.

Properties

discoverIpv6
bool discoverIpv6 [@property getter]
bool discoverIpv6 [@property setter]

If true, IPv6 is used for UPNPDevice discovery.

discoverLocalPort
long discoverLocalPort [@property getter]
long discoverLocalPort [@property setter]

If 0, the local port to use for discovery is chosen automatically by the system. If 1, discovery will be done from the source port 1900 (same as destination port). Otherwise, the value will be used as the port.

discoverMulticastIf
String discoverMulticastIf [@property getter]
String discoverMulticastIf [@property setter]

Multicast interface to use for discovery. Uses the default multicast interface if empty.

Static functions

_new
UPNP _new()

Construct a new instance of UPNP. Note: use memnew!UPNP instead.

Static variables

_classBindingInitialized
bool _classBindingInitialized;
Undocumented in source.

Structs

GDNativeClassBinding
struct GDNativeClassBinding
Undocumented in source.

Unions

__anonymous
union __anonymous
Undocumented in source.

Variables

_GODOT_internal_name
enum string _GODOT_internal_name;
Undocumented in source.

Mixed In Members

From mixin baseCasts

as
inout(To) as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
inout(To) as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
inout(ToRef) as()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(ToRef)
Undocumented in source.
opCast
void* opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
godot_object opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
bool opCast()
Undocumented in source. Be warned that the author may not have intended to support it.

Detailed Description

const PORT = 7777 var upnp = UPNP.new() upnp.discover(2000, 2, "InternetGatewayDevice") upnp.add_port_mapping(port)

To close a specific port (e.g. after you have finished using it):

upnp.delete_port_mapping(port)

Meta