SFML community forums

Help => Network => Topic started by: Merle on October 23, 2018, 09:29:12 pm

Title: UDP socket connection over WAN
Post by: Merle on October 23, 2018, 09:29:12 pm
Hello,

I’ve been working on an online game for around a month and a half now, and I have made a lot of progress. I have a whole system in place for connecting different machines over LAN, sending packets full of player data to the server and then sending all the data to other players, and all the other basics of online games. I thought it was impossible to connect UDP sockets over WAN without some form of NAT traversal, like UDP hole punching, but I was looking through some tutorials and I found out this might not be the case.

How exactly would this work in SFML, and what would I need to do this? Would I need hole punching after all? Has somebody already done this, and is there any source code for something like this?
Title: Re: UDP socket connection over WAN
Post by: eXpl0it3r on October 23, 2018, 09:50:54 pm
NAT hole punching (https://en.wikipedia.org/wiki/Hole_punching_(networking)) isn't specific to any library, but just requires an external server that you contact from inside the network, then the router will allow traffic over the opened ports and you're good to go.

I don't know of anyone who's implemented it with SFML, but it shouldn't be too difficult to get it right.

I also recommend to read the networking section in the FAQ (https://www.sfml-dev.org/faq.php#networking), might safe you some time by help steering around some issues. ;)
Title: Re: UDP socket connection over WAN
Post by: Merle on October 23, 2018, 11:15:23 pm
Thanks for the quick response.

So does this mean I'll have to use a separate server for connecting them if I want them to connect no matter what? And how exactly does that work? Could you, perhaps, just send all the information you need over something like discord, or is there more to it than just transferring the information?
Title: Re: UDP socket connection over WAN
Post by: eXpl0it3r on October 23, 2018, 11:19:39 pm
Afaik that's how hole punching works, yes.

I don't have any more information for you. Just go read how the protocol works and then implement it. As I said, I don't know of anyone who's done and shared it, so you have the chance to be the first. ;)

Edit: Actually quickly googled and there are also different approaches to NAT traversal, not sure what's the best/easiest to implement. Have fun doing some research! ;)

https://tools.ietf.org/html/rfc7604
https://tools.ietf.org/html/rfc5128
https://github.com/maidsafe/rfcs/blob/master/text/0008-udp-hole-punching/0008-udp-hole-punching.md
...