Search Unity

NAT Punchthrough

Discussion in 'Multiplayer' started by Zelre, Sep 14, 2019.

  1. Zelre

    Zelre

    Joined:
    Dec 3, 2016
    Posts:
    55
    Hi,

    I'm currently an Indie developer working on games in the spare time I get after and before work... Everything I know is self taught and through online youtube tutorials and documentation. With that being said, I haven't had much time to really get into networking, and the game I'm currently working on will only have 2 players playing against each other at a time...

    Currently, my plan is to have a "Play" button on the home screen. Player clicks play, game searches for any rooms available that match the player's rating (or come within like 30 points of it) and then joins the first room available. If none are available, a new room will be created.

    To connect to a server, you'd enter the IP and port and bam, you're in... So what makes it so hard for a player to hit Play, their device's host IP and an open port gets entered into the database, and the joining player connects directly to that? I know this isn't the most secure method, but for now I just need to get something like this to work, and I can build on securing it or finding a better solution later...

    Unless someone has a better solution for a simple host or join 1v1 system that doesn't require some huge CCU relay server...
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Pretty much every player is using a device which is behind a NAT router. When you host a server behind a NAT router, and a client attempts to connect to it, the request hits the NAT router and it has no idea where to send it.

    For home PC's you can log into your router and manually add a port forwarding rule. When on a network such as a school network, corporate network, 4G wireless network, etc, etc, that is usually not possible. So you need a server which connects the two clients together, either via NAT punchthrough (connecting two clients together instead of one acting as a typical server) or relay, which are the typical approaches to the problem. .

    Research NAT for more information.
     
    andrew-lukasik and samuelFenton like this.
  3. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
  4. Zelre

    Zelre

    Joined:
    Dec 3, 2016
    Posts:
    55
  5. Zelre

    Zelre

    Joined:
    Dec 3, 2016
    Posts:
    55
    Thanks, looks like I need to spend a lot more time looking into networking later when I get to that stage... Focusing on all the things I can currently do right now, then I'll research more into the things I can't. ;)