Search Unity

Failed to connect to master server

Discussion in 'Multiplayer' started by EdgarCarrera, Jul 27, 2014.

  1. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    Hello guys can you help me why i got this error?

    Failed to connect to master server at 67.225.180.24:23466

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System;
    4.  
    5. public class NetworkManager : MonoBehaviour
    6. {
    7.     public GUISkin MySkin;
    8.     public GameObject myCharacter;
    9.  
    10.     private string serverName = "", maxPlayers = "5", port = "25566";
    11.     private Rect windowRect = new Rect(0, 0, 400, 400);
    12.  
    13.     private void Awake()
    14.     {
    15.         DontDestroyOnLoad (gameObject);
    16.     }
    17.  
    18.     private void OnGUI()
    19.     {
    20.         GUI.skin = MySkin;
    21.         if(Network.peerType == NetworkPeerType.Disconnected)
    22.         {
    23.             windowRect = GUI.Window (0, windowRect, windowFunc, "Servers");
    24.  
    25.             GUILayout.Label("Server Name");
    26.             serverName = GUILayout.TextField(serverName);
    27.  
    28.             GUILayout.Label("Port");
    29.             port = GUILayout.TextField(port);
    30.  
    31.             GUILayout.Label("Max Players");
    32.             maxPlayers = GUILayout.TextField(maxPlayers);
    33.  
    34.             if(GUILayout.Button("Create Server"))
    35.             {
    36.                 try
    37.                 {
    38.                     Network.InitializeSecurity();
    39.                     Network.InitializeServer(int.Parse(maxPlayers), int.Parse(port), !Network.HavePublicAddress());
    40.                     MasterServer.RegisterHost("MMORPG Server", serverName);
    41.                 }
    42.                 catch(Exception)
    43.                 {
    44.                     print("Please type in numbers for port and max players");
    45.                 }
    46.             }
    47.         }
    48.         else
    49.         {
    50.             if(GUILayout.Button("Spawn"))
    51.             {
    52.                 Network.Instantiate(myCharacter, transform.position, transform.rotation, 0);
    53.                 GetComponent<Camera>().enabled = false;
    54.                 GetComponent<AudioListener>().enabled = false;
    55.             }
    56.  
    57.             if(GUILayout.Button("Disconnect"))
    58.             {
    59.                 Network.Disconnect();
    60.             }
    61.         }
    62.     }
    63.  
    64.     void OnServerInitialized()
    65.     {
    66.         Application.LoadLevel ("World1");
    67.     }
    68.  
    69.     void OnConnectedToServer()
    70.     {
    71.         Application.LoadLevel ("World1");
    72.     }
    73.  
    74.     private void windowFunc(int id)
    75.     {
    76.         if(GUILayout.Button("Refresh"))
    77.         {
    78.             MasterServer.RequestHostList("MMORPG Server");
    79.         }
    80.  
    81.         GUILayout.BeginHorizontal ();
    82.  
    83.         GUILayout.Box ("Sever Name");
    84.  
    85.         GUILayout.EndHorizontal ();
    86.  
    87.         if(MasterServer.PollHostList().Length != 0)
    88.         {
    89.             HostData[] data = MasterServer.PollHostList();
    90.             foreach(HostData c in data)
    91.             {
    92.                 GUILayout.BeginHorizontal();
    93.                 GUILayout.Box(c.gameName);
    94.                 if(GUILayout.Button("Connect"))
    95.                 {
    96.                     Network.Connect(c);
    97.                 }
    98.                 GUILayout.EndHorizontal();
    99.             }
    100.         }
    101.  
    102.         GUI.DragWindow(new Rect(0, 0, Screen.width, Screen.height));
    103.     }
    104. }