title: How to connect to our own dedicated server using photon networking in unity?(Self-hosted)
body: <p>In below script am trying to connect my game with my own server. But every time I get an error like</p>
  <blockquote>
  <p>-(JoinRandomRoom failed. Client is on MasterServer (must be Master Server for matchmaking) but not ready for operations (State: ConnectingToMasterServer). Wait for callback: OnJoinedLobby or OnConnectedToMaster.)</p>
  </blockquote>
  <p>please check my below script and check what is wrong.</p>
  <pre><code>[SerializeField] private GameObject FindOppenentTxt = null;
  [SerializeField] private GameObject waitingStatusPanel = null;
  [SerializeField] private Text waitingStatusText = null;
  
  private bool isConnnecting = false;
  
  [SerializeField]
  private const string GameVersion = &quot;1.1&quot;;
  
  private const int maxPlayer = 2;
  
  private string masterServerAddress = &quot;**********&quot;;
  private int port = 7777;
  private string appID = &quot;*************7d645e794534&quot;;
  
  private void Awake()
  {
      PhotonNetwork.AutomaticallySyncScene = true;
  }
  
  private void strart()
  {
      PhotonNetwork.SendRate = 20;
      PhotonNetwork.SerializationRate = 5;
      PhotonNetwork.ConnectToMaster(masterServerAddress, port, appID);
      //PhotonNetwork.ConnectUsingSettings();
  }
  
  public void FindOpponent()
  {
      isConnnecting = true;
      FindOppenentTxt.SetActive(false);
      waitingStatusPanel.SetActive(true);
      waitingStatusText.text = &quot;Searching...&quot;;
  
      if(PhotonNetwork.IsConnected)
      {
          PhotonNetwork.JoinRandomRoom();
          Debug.Log(&quot;findingRoom&quot;);
      }
      else
      {
          //PhotonNetwork.CreateRoom(null, new RoomOptions { MaxPlayers = maxPlayer });
          Debug.Log(&quot;creatingRoom&quot;);
          PhotonNetwork.GameVersion = GameVersion;
          //PhotonNetwork.ConnectUsingSettings();
          PhotonNetwork.ConnectToMaster(masterServerAddress, port, appID);
          Debug.Log(PhotonNetwork.CurrentRoom);
      }
  }
  
  public override void OnConnectedToMaster()
  {
      if(isConnnecting)
      {
          PhotonNetwork.JoinRandomRoom();
          Debug.Log(&quot;Server IP: &quot; + PhotonNetwork.ServerAddress);
      }
  }
  
  public override void OnDisconnected(DisconnectCause cause)
  {
      waitingStatusPanel.SetActive(false);
      FindOppenentTxt.SetActive(true);
      Debug.Log(&quot;disconnected&quot;);
  }
  
  public override void OnJoinRandomFailed(short returnCode, string message)
  {
      Debug.Log(&quot;There are no clients&quot;);
      PhotonNetwork.CreateRoom(null, new RoomOptions { MaxPlayers = maxPlayer });
  }
  
  public override void OnJoinedRoom()
  {
      Debug.Log(&quot;Joined a room ssuccessfully&quot;);
      int playerCount = PhotonNetwork.CurrentRoom.PlayerCount;
      if(playerCount != maxPlayer)
      {
          waitingStatusText.text = &quot;waiting for an opponent&quot;;
      }
      else
      {
          waitingStatusText.text = &quot;Opponent Found...please wait..&quot;;
      }
  }
  
  public override void OnPlayerEnteredRoom(Player newPlayer)
  {
      if (PhotonNetwork.CurrentRoom.PlayerCount == maxPlayer)
      {
          PhotonNetwork.CurrentRoom.IsOpen = false;
          waitingStatusText.text = &quot;opponent in room&quot;;
  
          PhotonNetwork.LoadLevel(&quot;MainScene&quot;);
      }
  }
  </code></pre>