Godot Version
Godot 4.2
Question
func upnp_setup():
var upnp = UPNP.new()
#
var discover_result = upnp.discover()
assert(discover_result == UPNP.UPNP_RESULT_SUCCESS, \
"UPNP Discover Failed! Error %s" % discover_result)
assert(upnp.get_gateway(), \
"UPNP Invalid Gateway!")
var map_result = upnp.add_port_mapping(PORT)
assert(map_result == UPNP.UPNP_RESULT_SUCCESS, \
"UPNP Port Mapping Failed! Error %s" % map_result)
print("Success! Join Address: %s" % upnp.query_external_address())
The code works fine up until get_gateway() and I have no clue why. Someone help I do not know what I am doing.
Same code works for me. I’d guess your router or network setup doesn’t like it. What do you get from get_device_count()
? And for each of those devices what does igd_status
say?
1 Like
It only came up with one device, and I’m not sure how to use igd_status
I dont know if this helps but the game stops running whenever i try to close it
unit327
February 12, 2024, 11:50pm
6
Try it on a different network at a friend’s house or something and it will probably work. Upnp support is flaky on a lot of routers.
Upnp isn’t a real solution anyway. Maybe if you are working on something just for yourself but it doesn’t work for the general public. ISP’s generally implement CGNAT these days which means port forwarding doesn’t work. You’ll need something else, dedicated servers, UDP hole punching etc.
bepis
February 13, 2024, 1:32am
7
I opened an issue about this last week when I ran into the same problem:
opened 06:21PM - 04 Feb 24 UTC
bug
needs testing
topic:network
### Tested versions
Godot v4.2.stable
### System information
Godot v4… .2.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3060 Ti (NVIDIA; 31.0.15.3742) - AMD Ryzen 5 5600X 6-Core Processor (12 Threads)
### Issue description
Calling `discover()` on a new UPNP instance works as expected and my router shows up as one of the devices found. However, `get_gateway()` always returns null without any further messages. UPNP is enabled on the router.
Router:
![image](https://github.com/godotengine/godot/assets/24302976/77adadbf-4b58-4b4e-bc01-b84526b67f7e)
Script:
```gdscript
extends Node3D
func _ready():
var upnp = UPNP.new()
var upnp_result = upnp.discover(2000, 2, "")
if upnp_result == OK:
for i in upnp.get_device_count():
var device = upnp.get_device(i)
print("Description URL: " + str(device.description_url))
print("IGD Status: " + str(device.igd_status))
print("Is Valid Gateway: " + str(device.is_valid_gateway()))
print(upnp.get_gateway())
else:
print("UPNP discover not OK: " + str(upnp_result))
```
Godot reports the IGD status as 5 or "Not Connected". I downloaded the miniupnpc client and added the mapping directly through the CLI. It also reported the status as not connected but continued anyway and worked successfully.
![image](https://github.com/godotengine/godot/assets/24302976/60b082b7-0ccf-4a6b-96dc-9313cdcad298)
I'm not sure if this would still be considered a bug but I wonder if it's possible for Godot to behave this way as well since the mapping can still be added even with the not connected status.
### Steps to reproduce
1. Create a new UPNP instance
2. Call `upnp.discover()`
3. Check `upnp.get_gateway()`
### Minimal reproduction project (MRP)
[demo.zip](https://github.com/godotengine/godot/files/14157856/demo.zip)
But yeah, I quickly found out that UPNP is not what most games use anyway.
i’m also making a multiplayer game and i found out that when testing the game in the godot engine it doesn’t work so i remove it to test and then when i export the game i add it back in
UPnP is a security risk waiting to happen and would be turned off by default on all routers if I have my way.
Is UPnP a Security Risk? (howtogeek.com)