Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: UDP socket connection over WAN  (Read 3980 times)

0 Members and 1 Guest are viewing this topic.

Merle

  • Newbie
  • *
  • Posts: 17
    • View Profile
UDP socket connection over WAN
« 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11039
    • View Profile
    • development blog
    • Email
Re: UDP socket connection over WAN
« Reply #1 on: October 23, 2018, 09:50:54 pm »
NAT hole punching 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, might safe you some time by help steering around some issues. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Merle

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: UDP socket connection over WAN
« Reply #2 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11039
    • View Profile
    • development blog
    • Email
Re: UDP socket connection over WAN
« Reply #3 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
...
« Last Edit: October 23, 2018, 11:22:14 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/