Search Unity

Player Hosted Multiplayer

Discussion in 'Multiplayer' started by Idkman3, Oct 13, 2019.

  1. Idkman3

    Idkman3

    Joined:
    Sep 23, 2019
    Posts:
    6
    Hello!

    How do you make a system were the player host their own server on their own pc with no cost? Almost like the open to lan option in minecraft but you don't have to be on the same router.
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    As I mentioned in your other thread, the hosting the server part is easy. Most network API's work this way. The problem you have is asking your users to log into their router and set up port forwarding from the router to the internal IP address of their server. If you're fine with that, then most network API's will work out of the box for you. You'd just have the person setting up the server log into their router, do the port forwarding, and then tell the other player's the external IP address of their router for everyone else to connect to.

    If you instead want a server browser as part of your game client, and not require users hosting a server to set up port forwarding in their router, that's where the complications are. You'd need to set up your own master server for maintaining the list of all game servers, and implement a solution for getting around everyone's NAT routers (like pretty much all modern games). That is typically either a relay server or a technique called NAT punchthrough. A relay server is where the game server and all game clients make client connections to your server, and your server relays all packets between them. NAT punchthrough is where again everyone connects to your server, but your server then through a bit of trickery connects those clients together directly (it is more prone to failure, but uses a lot less of your bandwidth). There's lots of discussion on both topics on this forum you should have little problem finding.
     
    gooby429 and tobiass like this.