![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | MadMelon999 |
I am currently making a game that requires a direct connection across separate computers. Here are the relevant parts of my code:
const PORT = 5820
const MAX_PLAYERS = 8
func setup_host():
var peer = NetworkedMultiplayerENet.new()
peer.create_server(PORT, MAX_PLAYERS)
main.get_tree().network_peer = peer
is_server = main.get_tree().is_network_server()
func setup_client():
var peer = NetworkedMultiplayerENet.new()
peer.create_client(get_my_ip_address(), PORT)
main.get_tree().network_peer = peer
const my_number = 9 # I have tried every single one, but 9 is the index of what the preferred connection is for windows (I used terminal to find this)
func get_my_ip_address(my_number):
return IP.get_local_addresses()[my_number]
I have successfully tested this when running two instances of the application on my computer (same computer, and any ip address worked also). I have not yet tried local multiplayer on separate computers.
I cannot figure out how to make this work with separate computers on different networks. I have tried every single entry in IP.get_local_addresses() (which itself is a combination of different IPV4 [local] and IPV6 [internet] connections). I am also using a windows computers, and my friend is on the same platform. I don’t know if its just the platform, my code, or the windows firewall blocking the connection (I highly doubt its the firewall).
I have a few theories on how to solve this issue, but I can’t make them work.
- The first is to instead put a link like www.my_site.com instead of the IP address (I read that somewhere), but games like minecraft using direct connect just use IP addresses and Port Numbers to connect with each other, so I know there has to be a way around this. (Take a look at the last link in this chain, because I think that’s the only I way I can think of using an ip and port in a web address.)
- The second is not using NetworkedMultiplayerENet, but again, I have not found anything that uses explicitly direct connect (I.E. not a web address). If it does require a web connection in the end and I do need to connect to a website, I want it to be free and, if acting as a server, running at all times.
Please tell me ways on how to solve this. I have looked everywhere and have come up empty handed. I promise I’ll make a youtube video or something once I learn the solution, because honestly, this stuff should be more accessible.
Here are some links if you are new to the issue:
GODOT tutorial on how to do multiplayer (fails to explain what IP to use): High-level multiplayer — Godot Engine (stable) documentation in English
Says to use vpn/paid thing to host server, but I want a direct connection: https://forum.godotengine.org/65774/how-to-connect-to-a-server-outside-of-local-network
Gives several ways to solve the problem, a good lead, however, the tutorial inside this link on Direct Connection is the link below, and it lacks crucial information: https://forum.godotengine.org/43665/how-connect-two-device-with-live-server-not-localhost-godot
This one literally explains everything, but they fail to explain what IP to use: Godot dedicated server tutorial | Tom Langwaldt's Blog
It should also be noted that every multiplayer godot tutorial I have ever seen either tests it on the same computer or on a local network, never in separate locations with separate computer with separate web connections.
This one looks promissing, however, I haven’t tested it out yet, I will respond to this Q&A chain when I find the solution: Reddit - Dive into anything
Thank you so much for your help