Skip to content

Instantly share code, notes, and snippets.

@vini-guerrero
Created January 29, 2019 00:37
Show Gist options
  • Save vini-guerrero/f5c04957646c6fa34b17dd9cdc5483b9 to your computer and use it in GitHub Desktop.
Save vini-guerrero/f5c04957646c6fa34b17dd9cdc5483b9 to your computer and use it in GitHub Desktop.
This snippet checks if the router is available to port forward using Godot's RPC system
extends Node2D
func _ready():
var port = 12345
var upnp = UPNP.new()
upnp.discover()
for i in range(upnp.get_device_count()):
var upnp_device = upnp.get_device(i)
print('device[',i,']:')
print('- igd_our_addr: ', upnp_device.igd_our_addr)
print('- igd_service_type: ', upnp_device.igd_service_type)
print('- igd_status: ', upnp_device.igd_status)
print('- service_type: ', upnp_device.service_type)
print('gateway:', upnp.get_gateway())
if upnp.get_gateway() and upnp.get_gateway().is_valid_gateway():
var res_udp = upnp.add_port_mapping(port, port, 'Godot', 'UDP')
var res_tcp = upnp.add_port_mapping(port, port, 'Godot', 'TCP')
print('res_udp:', res_udp)
print('res_tcp:', res_tcp)
else:
print('no valid gateway')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment