UPNP not working, get_gateway() failing

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 :confused:

I dont know if this helps but the game stops running whenever i try to close it

How do i run igd_status?

@unit327

im sorry im desperate :frowning:

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.

I opened an issue about this last week when I ran into the same problem:

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)