CreggHancock / HolePuncher

UDP Holepunch plugin for Godot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Connection after holes punched?

wapordev opened this issue · comments

So I'm trying to use this for a little project, but having a little trouble. I actually got a linux server to host the server.py, because I wasn't sure if it would work 100% running locally, and now I can connect to the server with a friend, and it shows our connections, says "Peer info has been sent. Terminating Session", and the client's recieve the info.

But what now? if I try creating a server like normal:

var net = NetworkedMultiplayerENet.new()
net.create_server(my_port, 2)
get_tree().set_network_peer(net)

I get an error about it not being able to create, with no other info. I also thought to delay the server creation for like a second, as maybe the port was being occupied in that moment (I don't know much about this stuff), but then the result is no errors, but the clients can't connect, as if there was no holepunching in the first place.

Am I doing something wrong? Is the code outdated and won't work? Do our computers not support this or something?

Yes you will likely have to wait a few seconds in between to make sure the holepunch scene isn't using it anymore, you were on the right track about that.

When I got it working I first did a single yield(get_tree(), "idle_frame")

Then I checked to see if my client was the host or not using $HolePunch.is_host

if they were the host I created a timer and waited another couple of seconds just for safe measure. Then I created an enet server at the HolePunch's own_port.

if they were the client (not the host) I created a timer and waited 10 seconds (to give the hosting player time to create their server). Then I joined a created a client with CreateClient($HolePunch.host_address, $HolePunch.host_port, 0, 0, $HolePunch.own_port)

Obviously you may need to change the address of the HolePunch node, but hopefully that gives you the jist of things. I did get it working using this logic, but since then I've gotten a router that doesn't work with UDP holepunching at all so I can't test it which is why an example hasn't been made yet. Next time I get a router I will try to avoid those pesky Symmetric NAT's that stop UDP holepunching.

Thanks for the quick response!
Ok I'll definitely try that setup when I get the chance.
Also, is there any way to tell if my router doesn't work with it? Like I said, the server looked like it was able to succesfully connect, but I don't know what the behaviour would be if holepunching didn't work on my router.

Edit:

Obviously you may need to change the address of the HolePunch node

yeah I've set that to my server ip and port

I've implemented your method, now just waiting for my friend to test it

ok sick it works! tysm for the plugin and the help.
Since networking is annoying, I decided to tackle that first, and so my project is basically barebones implementation of this.
I could polish it up, and publish it as an example if you want.

oh also, I changed one line of your code: from get_node("/root/").add_child(p_timer) to get_node("/root/").call_deferred("add_child", p_timer).
I don't exactly know what this changes, but I was getting an error previously, and godot suggested the latter. It might have something to do with my room setup?

Oh yeah you can probably submit a pr to add the call_deferred change. Not sure why I've not seen that error before, but when instancing nodes in a _ready() using call_deferred is usually advised.

And sure an example would be more than welcome! you are welcome to submit a PR for that as well.

I'm going to go ahead and close this issue as it seems to be resolved, but if you open a PR for an example we can review and discuss details on that there. Thank you!