How to use UPnP with P2P networking
In this recipe, we will use the UPnP class to port-forward, which is used in P2P networking. We will create a new scene, then add a script to the Node2D node, which searches for ports that can be forwarded, and then forward the port. The script can be used in your multiplayer game to look for internal and external ports and gateways (routers).
Getting ready
For this recipe, click the + button to the right of the Character scene we just completed to add a new scene. In the Scene tab, click 3D Scene. Click on the word Scene in the main menu next to Project, then select Save Scene As, and name it UPNP
.
How to do it…
First, we will add an empty script to the Node2D node in the Scene tab:
- Left-click on the Node2D node in the Scene tab.
- In the Inspector tab, click on <empty> to the right of Script.
- Left-click on New Script from the drop-down list.
- In the Attach Node Script window, uncheck the checkbox to the...