0 votes

Hello all,

I've been mucking around with Godot's high level networking API and managed to get a simple LAN chat room working. When I tried to connect via an external IP and port forwarding, however, the connection fails. Here's my current setup:

Server code:

extends Node

var host_ip
var port = 42424

var registered_users = {}

func _ready():

func _on_peer_connected(peer_id):
    print(str(peer_id) + " connected.")

func _on_peer_disconnected(peer_id):
    print(str(peer_id) + " disconnected.")

func host_server():
    var network = NetworkedMultiplayerENet.new()
    if network.create_server(port,2) != OK:
        print("Failed to create server. Aborting....")

    host_ip = get_node("ServerConfigWindow/VBoxContainer/LineEdit").text

    print("Server initialized.\nIP: " + host_ip + "\nPort: " + str(port))

func _on_host_button_pressed():

remote func register_user(peer_id, username):
    registered_users[peer_id] = username
    get_node("ChatWindow").print_text(peer_id, "(has joined the chat)")

func get_registered_users():
    return registered_users

Client code:

extends Node

var host_ip
var port = 42424

func _ready():

func _on_connection_succeeded():
    print("Connected to server at " + host_ip + ":" + str(port))

func _on_connection_failed():
    print("Failed to connect to server at " + host_ip + ":" + str(port))

func connect_to_server():
    print("Trying to connect....")
    var client = NetworkedMultiplayerENet.new()
    if client.create_client(host_ip,port) != OK:
        print("Failed to connect to server at " + host_ip + ":" + str(port))

func _on_connect_button_pressed():
    host_ip = get_node("ConnectWindow/VBoxContainer/LineEdit").text

The IP address gets determined by user input. When I connect to the server using an IP address my LAN can see, everything works fine. When I try to connect with the IP that the external network sees, the connection fails. Note that I do have port forwarding set up for the port 42424. Any ideas why I might be running into this issue?

in Engine by (74 points)

does seems to be an issue with your entwork. can descripe your setup more detailed? where do your computers are connected to?

I realize this is a very old question but will offer a possible explanation. You appear to be attempting to connect to your ISP assigned public IP. In many cases, ISPs intentionally (or accidentally) block such attempts in the interest of security. It prevents customers on the same sub-net from launching hack attempts against their neighbors. Most, but not all, modern firewall/routers recognize out-going traffic destined for its own public IP and will loop-back internally. The catch is that the the out-bound and in-bound ports cannot be the same.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.