Created
January 29, 2019 00:37
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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