What is the correct way to change network_peer (change server)?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sapporovhs

I am running two independent games, each connecting to a headless Godot server successfully by creating ENet clients and doing the standard get_tree().set_network_peer(client).

After two players have connected the server sends each the ip address and port of the other and I would like to have the two client sessions then cleanly close their connections to the server and connect to each other in a new server-client ENet connection. The clients are correctly getting each others’ address and port, and one is correctly making a new server and setting get_tree().set_network_peer(match_server) while the other is correctly doing a get_tree().set_network_peer(match_client). I’m constructing and setting as I do in _ready() to connect to the remote match making server. However the new matched server-client ENet pair are not able to connect.

If I hard code the ip/port of each device, and bypass the match making server, they connect fine. It’s only when I first connect to the match making server, receive the match’s info, close the server connection that the peer to peer connection fails.

I can provide code after I clean it up a bit. I’m wondering what I might be missing here. Thanks in advance!