Click or drag to resize

UPNPAddPortMapping Method

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(Int32, Int32, String, String, Int32) 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 UPNPUPNPResult for possible return values.

Namespace:  Godot
Assembly:  GodotSharp (in GodotSharp.dll) Version: 1.0.0
Syntax
C#
public int AddPortMapping(
	int port,
	int portInternal = 0,
	string desc = "",
	string proto = "UDP",
	int duration = 0
)

Parameters

port
Type: SystemInt32

[Missing <param name="port"/> documentation for "M:Godot.UPNP.AddPortMapping(System.Int32,System.Int32,System.String,System.String,System.Int32)"]

portInternal (Optional)
Type: SystemInt32

[Missing <param name="portInternal"/> documentation for "M:Godot.UPNP.AddPortMapping(System.Int32,System.Int32,System.String,System.String,System.Int32)"]

desc (Optional)
Type: SystemString

[Missing <param name="desc"/> documentation for "M:Godot.UPNP.AddPortMapping(System.Int32,System.Int32,System.String,System.String,System.Int32)"]

proto (Optional)
Type: SystemString

[Missing <param name="proto"/> documentation for "M:Godot.UPNP.AddPortMapping(System.Int32,System.Int32,System.String,System.String,System.Int32)"]

duration (Optional)
Type: SystemInt32

[Missing <param name="duration"/> documentation for "M:Godot.UPNP.AddPortMapping(System.Int32,System.Int32,System.String,System.String,System.Int32)"]

Return Value

Type: Int32

[Missing <returns> documentation for "M:Godot.UPNP.AddPortMapping(System.Int32,System.Int32,System.String,System.String,System.Int32)"]

See Also