Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Multiplayer Without Matchmaker or Relay.

Discussion in 'Multiplayer' started by TwoTen, Oct 17, 2016.

  1. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Hello!
    So I have gotten to the point of understanding how things work with multiplayer and UNet. My game is coming along nicley. I am at a big question atm however. I have currently built my own matchmaking system. Registering servers work perfectly and other people can request to get a list of all servers. The list contains an IP, port and some other information.

    What I am trying to do right now is to get the NetworkManager to connect to a direct IP. But for this I would need port forwarding (from my understanding). I have tried to read around on the topic. But I don't quite understand the differences. What is the difference between automatic portforwarding, NAT punchthrough. or UPNP. What do I need to simply connect with StartClient() using a direct IP and port. What are the differences and what would best fit my needs?


    Thank's alot.
     
  2. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,102
    Hi
    First of all , if you host game servers yourself on server machines with public IP, There would be no issues to connect to them and you don't need port forwarding.

    Now on Port forwarding.
    Most users of the internet in homes/offices are connected to the internet in a way that they share a public IP with many others and/or are behind home/office routers so an IP address is used for multiple machines. In order to be able to address an specific machine which host your game you need to tell the router to forward all traffics to a specific port of the public IP to the specific machine on a specified port. And the public IP should be static (i.e. should not change over time).
    NAT/uPnP are techniques to connect users behind firewalls and routers to each other without port forwarding and are not guaranteed to always work and are not directly supported on uNet yet. There are asset store packages to add the functionality and they are on uNet's roadmap IIRC as well. The techniques UDP hole punching, NAT punch through and ... are usually referring to the same thing. I'm not going to talk their details but they allow you to connect to a machine which shares its public IP with others without port forwarding and the technique fails 10%-25% of the time as I've read on gathered statistics.

    Unity's Match making server also can solve the problem by using a relay server. The way it works is that your client and server connect to unity's relay server and the relay server is using public addresses and is always accessible to everyone. Now when your client and server want to exchange data, they both send the data to the relay server and the relay server sends the data to the intended parties. This adds some amount of delay but removes the need to host your own servers. also in this approach the servers are in user's hands to modify and hack and cheat and this might/might not be ok depending on your scenario.
     
  3. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Hi. Thanks for your reply. After testing some further. If the server host simply port forwards everything work perfectly. But what is your recomendation for me to do? Use something like NAT punchthrough or any other tactics? Cause If the host simply port forwards then it seems to be all good. And yes, servers are hosted on user machines.
     
  4. Vedrit

    Vedrit

    Joined:
    Feb 8, 2013
    Posts:
    514
    Most games where users are permitted host their own servers, instructions on how to configure port-forwarding is provided, since, as Ashkan_gc said, port-forwarding is the most reliable way.
    However, it could be said that punchthrough or similar methods are more convenient for less-experienced users or casual servers that don't need reliability.
    I'd say it's up to you.
     
  5. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    So after researching even more and deciding that user hosting is the way I want to go with I have just a few additional questions.

    My plan is the following: Add to my master server the ability to store info about every client connected to the server. While the match is on each client will recieve a connection rating. If the host disconnects every client will refer to the client with highest connection rating and connect to him. And there I have host migration.

    So what I need is for players to be able to simply press Join. it will then choose to create or join a server. It will attempt to do punchthrough. Is there any good libraries / ways to do NAT Punchthrough where I can get a bool if it was successful or not.
    And will the NAT punchthrough only be required on the Host AKA server? Because if that's the case I can deal with the ones trying to become a host but fails to do punchthrough in my matchmaking system making it fairly easy.

    Is there any libraries that fit my needs? Or maybe even ways in .net. Thank's in advance guys.