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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How can i host multiple games on the same server / IP ?

Discussion in 'Multiplayer' started by Paradoks, Dec 13, 2015.

  1. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    436
    Hi ,

    I got my game allready running on a AWS EC2, so i got one ip adress only.
    I wonder, how can i host multiple games on this server ?

    Let's say: i would like to make a kind of lobby where the player could select the game he wants to join.
    How can i perfom that ?

    Can i make numerous games with different ports used ?
    I was about to make a dirty thing with the NetworkDiscovery, but before i begin i wanted to have some ideas/advices maybe.

    Thanks,
     
  2. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    436
    Nobody on that ?
     
  3. ObliviousHarmony

    ObliviousHarmony

    Joined:
    Jul 3, 2014
    Posts:
    79
    Hello,

    Different ports are indeed your solution. In a typical use case, only a single application can listen to a given port at once.

    Edit: A more full answer would be to have a master server that all of the servers can connect to. If having "dynamic" server ports is something you desire, you could have it so that on initialization your server connects to this "master" server, and checks to see if the port is taken for that IP. If it is, you can tell the server that it should listen on a different port. Once the master server tells it what port to listen on, it can initialize the server proper.

    This also will give you a server that contains a list of all other servers, and can be used for server browsing, matchmaking, metric collection, etc.
     
    Last edited: Dec 14, 2015
  4. jathrek

    jathrek

    Joined:
    Jul 16, 2015
    Posts:
    36
    The NetworkManager component allows you to define the port used for both the server and the clients.
    But the default NetworkManagerHUD does not allow you to modify this port at runtime.

    I suppose you could simply change the value of the NetworkManager's port and foresee, in the future, to implement a custom UI that would contain a field for the port and that value would be used accordingly (by doing a bit of custom code, like in the sample here: http://docs.unity3d.com/Manual/UNetClientServer.html) when creating a server or joining a game.
     
  5. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    436
    In fact, i was going to try to make an auto connector for my linux headless server.
    the server tests a port with NetworkDiscovery to see if there is an answer on specific port:
    if no: connect.
    if yes change port and connect.

    but it sounds ugly, i wandered if there was a builtin way.
    Is there a simple way to check for a port used or not BTW ?
     
  6. jathrek

    jathrek

    Joined:
    Jul 16, 2015
    Posts:
    36
    As a client? I don't think so...
    The best you could do is hide this inside a black-box framework so you're not aware of all the ugly things happening, which in turns help you sleep during the night. ;-p