Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to host multiplayer servers at home?

Discussion in 'Multiplayer' started by JilkyGames, Aug 1, 2017.

  1. JilkyGames

    JilkyGames

    Joined:
    Aug 1, 2017
    Posts:
    1
    Okay, I am a complete beginner at unity and this question is more directed to my future self when i'm in a predicament about multiplayer games on unity. When I am making a unity game that has a multiplayer feature, say an MMO, How do I host the game on my own servers. I am planning to get a small server in the foreseeable future to host some game servers and a private cloud.

    What I mean is how do you host a game server at home 24/7 so people can play on your game, not using unity multiplayer or any 3rd party places like amazon. Thanks!
     
  2. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    If you are running something like Windows Server. And your server application is a exe. Double click on it or run it from the command prompt.

    If you run a Linux server. Make sure you have make it executable (chmod +x). Then you can run the application from the terminal. ./<fileName>.extension
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Set up your server, and assign it a static IP address or set a DHCP reservation for it on your router (so the IP address doesn't change later). When developing your game, you should choose the UDP or TCP ports your game's server build will use as part of that process. On your router you then forward those port numbers used by your game to the IP address you assigned your server.

    You then launch the game server build on your home server like any other application, though it is typical to use the command line switches that don't initialize the graphics interface of the game, or if your server is Linux you just build it as a headless build.

    Hopefully your router's public IP address doesn't change too often. You provide that address to people outside of your local network for them to connect to your game. You can typically find that address when logged into your router. You could also hard code it into your game but may have to make updates to the game if the router's public IP address changes.

    Personally, I subscribe to a dynamic DNS service and then hard code the domain name into the game so the players don't have to deal with entering my router's IP address. If you do so you have to choose a service your router supports, and configure your router to send IP address updates to that service.
     
  4. Molmez

    Molmez

    Joined:
    Feb 8, 2016
    Posts:
    7
    Sorry for the necropost but I wanted to ask Joe-Censored is there not security risks hosting from a home network? I am thinking of using a raspberry pi as a dedicated game server for a small mobile game I am making that doesn't require a lot of data to be transported. Do you think it would suffice? No more than 6 players per instance.
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Unity doesn't support ARM based Linux builds, though I've seen threads on installing Android on a pi to run Android Unity builds. Not sure if you can make headless builds for Android though, which would be ideal for a server. I recently got an Atom based passively cooled mini PC for just over $100 USD for a similar purpose I'm going to test out later this month, which I've installed regular x86_64 Ubuntu server on. Might be a better choice for a Unity game server.

    (retiring my energy hog FX 8350 based home server, and turning it into a basic game machine for my 10 year old since he doesn't have his own computer)

    As far as security, well generally you would only forward the ports your game is using from your router to your server. I don't think the risks are particularly high doing it that way. If you forward ports to an apache or ssh server you'll have to take more care in locking those services down.