doc: UPNP: Add example on how to open/close a port
I have added a small code sample to show how to automate the process of port forwarding (and closing after you are done).
Thanks to @mhilbrunner for explaining how to achieve t0his (see #18780)
(cherry picked from commit 2a63853720
)
This commit is contained in:
parent
3e8b2d2063
commit
37e9ec842c
|
@ -5,6 +5,17 @@
|
||||||
</brief_description>
|
</brief_description>
|
||||||
<description>
|
<description>
|
||||||
Provides UPNP functionality to discover [UPNPDevice]s 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.
|
Provides UPNP functionality to discover [UPNPDevice]s 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:
|
||||||
|
[codeblock]
|
||||||
|
const PORT = 7777
|
||||||
|
var upnp = UPNP.new()
|
||||||
|
upnp.discover(2000, 2, "InternetGatewayDevice")
|
||||||
|
upnp.add_port_mapping(port)
|
||||||
|
[/codeblock]
|
||||||
|
To close a specific port (e.g. after you have finished using it):
|
||||||
|
[codeblock]
|
||||||
|
upnp.delete_port_mapping(port)
|
||||||
|
[/codeblock]
|
||||||
</description>
|
</description>
|
||||||
<tutorials>
|
<tutorials>
|
||||||
</tutorials>
|
</tutorials>
|
||||||
|
|
Loading…
Reference in New Issue