NetworkingPeer.Connect C# (CSharp) Method

Connect() public method

public Connect ( string serverAddress, ServerConnection, type ) : bool
serverAddress string
type ServerConnection,
return bool
    public bool Connect(string serverAddress, ServerConnection type)
    {
        if (PhotonHandler.AppQuits)
        {
            Debug.LogWarning("Ignoring Connect() because app gets closed. If this is an error, check PhotonHandler.AppQuits.");
            return false;
        }

        if (PhotonNetwork.connectionStateDetailed == global::PeerState.Disconnecting)
        {
            Debug.LogError("Connect() failed. Can't connect while disconnecting (still). Current state: " + PhotonNetwork.connectionStateDetailed);
            return false;
        }

        // connect might fail, if the DNS name can't be resolved or if no network connection is available
        bool connecting = base.Connect(serverAddress, "");
        if (connecting)
        {
            switch (type)
            {
                case ServerConnection.NameServer:
                    State = global::PeerState.ConnectingToNameServer;
                    break;
                case ServerConnection.MasterServer:
                    State = global::PeerState.ConnectingToMasterserver;
                    break;
                case ServerConnection.GameServer:
                    State = global::PeerState.ConnectingToGameserver;
                    break;
            }
        }

        return connecting;
    }

Same methods

NetworkingPeer::Connect ( string serverAddress, string applicationName ) : bool

Usage Example

Exemplo n.º 1
0
 public static bool ConnectUsingSettings(string gameVersion)
 {
     if (PhotonServerSettings == null)
     {
         Debug.LogError("Can't connect: Loading settings failed. ServerSettings asset must be in any 'Resources' folder as: PhotonServerSettings");
         return(false);
     }
     SwitchToProtocol(PhotonServerSettings.Protocol);
     networkingPeer.SetApp(PhotonServerSettings.AppID, gameVersion);
     if (PhotonServerSettings.HostType == ServerSettings.HostingOption.OfflineMode)
     {
         offlineMode = true;
         return(true);
     }
     if (offlineMode)
     {
         Debug.LogWarning("ConnectUsingSettings() disabled the offline mode. No longer offline.");
     }
     offlineMode                     = false;
     isMessageQueueRunning           = true;
     networkingPeer.IsInitialConnect = true;
     if (PhotonServerSettings.HostType == ServerSettings.HostingOption.SelfHosted)
     {
         networkingPeer.IsUsingNameServer   = false;
         networkingPeer.MasterServerAddress = PhotonServerSettings.ServerAddress + ":" + PhotonServerSettings.ServerPort;
         return(networkingPeer.Connect(networkingPeer.MasterServerAddress, ServerConnection.MasterServer));
     }
     if (PhotonServerSettings.HostType == ServerSettings.HostingOption.BestRegion)
     {
         return(ConnectToBestCloudServer(gameVersion));
     }
     return(networkingPeer.ConnectToRegionMaster(PhotonServerSettings.PreferredRegion));
 }
All Usage Examples Of NetworkingPeer::Connect
NetworkingPeer