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

Game client cannot connect to game server

Discussion in 'Multiplayer' started by DemocracyIsNonNegotiable, Nov 1, 2015.

  1. DemocracyIsNonNegotiable

    DemocracyIsNonNegotiable

    Joined:
    Aug 28, 2015
    Posts:
    7
    I have a VPS with a public IP of 52.26.76.224 and all of its ports are open.
    This VPS is running game server built from unity that will manage up to 500 active users (This is made possible due to an extremely low send rate of only 3 per second.

    I have a game client built from unity that I need to connect to the VPS on port 25001.

    For some reason this isn't working. I am completely clueless as to why and any support would be appreciated.

    VPS Game Server & VPS Screen.png Code:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ServerBoot : MonoBehaviour {
    5.  
    6.     private string IP = "52.26.76.224";
    7.     private int Port = 25001;
    8.  
    9.     public GUIStyle GUI_style_color_green;
    10.  
    11.     // Use this for initialization
    12.     void Start ()
    13.     {
    14.     }
    15.    
    16.     // Update is called once per frame
    17.     void Update ()
    18.     {
    19.    
    20.     }
    21.  
    22.     void OnGUI()
    23.     {
    24.         if (Network.peerType == NetworkPeerType.Disconnected)
    25.         {
    26.             Network.InitializeServer(32,Port);
    27.         }
    28.         if (Network.peerType == NetworkPeerType.Server)
    29.         {
    30.             GUI.Label (new Rect(25,25,250,25),"The server is running at IP: " + IP,GUI_style_color_green);
    31.             GUI.Label (new Rect(25,50,250,25),"Connections: " + Network.connections.Length,GUI_style_color_green);
    32.         }
    33.     }
    34. }
    My computer can ping the server....
    CMD good.png

    Server ports are open...

    Ports open.png

    Here is the code my game client is running...
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class NetworkTest : MonoBehaviour
    5. {
    6.  
    7.     private string IP = "52.26.76.224";
    8.     private int Port = 25001;
    9.  
    10.     public GUIStyle green;
    11.  
    12.     void OnGUI()
    13.     {
    14.         if (Network.peerType == NetworkPeerType.Disconnected)
    15.         {
    16.             if (GUI.Button(new Rect(20,20,200,24),"Connect to server"))
    17.             {
    18.                 Network.Connect(IP,Port);
    19.                 Debug.Log ("Attempting to connect to server at: " + IP);
    20.             }
    21.         }
    22.         if (Network.peerType == NetworkPeerType.Client)
    23.         {
    24.             GUI.Label(new Rect(20,44,250,24),"You are connected to a server.",green);
    25.             if (GUI.Button (new Rect (20, 20, 200, 24), "Disconnect From Server"))
    26.             {
    27.                 Network.Disconnect(250);
    28.             }
    29.         }
    30.     }
    When I click connect in my game client it cannot find the server at IP 52.26.76.224.

    Maybe port 25001 is not open on my computer? If it is not, then I do not want to open it or use that port because that means anyone who buys the game would have to open it as well. I would rather use a different port that would be open by default for most users.

    I cannot figure out why this is not working and I am so frustrated by it.
     
  2. DemocracyIsNonNegotiable

    DemocracyIsNonNegotiable

    Joined:
    Aug 28, 2015
    Posts:
    7
    I found the solution. Since the VPS is running Microsoft Server 2012, you need to access the server via remote desktop and go to control panel. From there you go to windows firewall, and allow a program through the firewall. Select your server application, and allow it access both privately and publicly. That fixed my issue and I hope someone else doesn't go through 6 hours of brutal pain like I did while banging their head against a wall then in the end only to become profusely enraged in a fiery despise of themselves for not thinking of this very simple and elegant solution to start with. :)

    PS: The server IP is different in these pictures only because I was going nuts and trying everything, including a new IP. (Of course that didn't fix it :p) Solution1.png Solution2.png