public bool Start()
        {
            // all addresses for Photon region servers will contain a :port ending. this needs to be removed first.
            // PhotonPing.StartPing() requires a plain (IP) address without port or protocol-prefix (on all but Windows 8.1 and WebGL platforms).
            string address      = this.region.HostAndPort;
            int    indexOfColon = address.LastIndexOf(':');

            if (indexOfColon > 1)
            {
                address = address.Substring(0, indexOfColon);
            }
            this.regionAddress = ResolveHost(address);


            this.ping = this.GetPingImplementation();


            this.Done           = false;
            this.CurrentAttempt = 0;

            #if PING_VIA_COROUTINE
            GameObject go = new GameObject();
            go.name = "RegionPing_" + this.region.Code + "_" + this.region.Cluster;
            this.coroutineMonoBehaviour = go.AddComponent <MonoBehaviourEmpty>();        // is defined below, as special case for Unity WegGL
            this.coroutineMonoBehaviour.StartCoroutine(this.RegionPingCoroutine());
            #else
            SupportClass.StartBackgroundCalls(this.RegionPingThreaded, 0, "RegionPing_" + this.region.Code + "_" + this.region.Cluster);
            #endif

            return(true);
        }
Esempio n. 2
0
        public bool Start()
        {
            // all addresses for Photon region servers will contain a :port ending. this needs to be removed first.
            // PhotonPing.StartPing() requires a plain (IP) address without port or protocol-prefix (on all but Windows 8.1 and WebGL platforms).
            string address      = this.region.HostAndPort;
            int    indexOfColon = address.LastIndexOf(':');

            if (indexOfColon > 1)
            {
                address = address.Substring(0, indexOfColon);
            }
            this.regionAddress = ResolveHost(address);


            this.ping = this.GetPingImplementation();


            this.Done           = false;
            this.CurrentAttempt = 0;
            this.rttResults     = new List <int>(Attempts);

            #if PING_VIA_COROUTINE
            MonoBehaviourEmpty.Instance.StartCoroutine(this.RegionPingCoroutine());
            #elif UNITY_SWITCH
            SupportClass.StartBackgroundCalls(this.RegionPingThreaded, 0);
            #else
            SupportClass.StartBackgroundCalls(this.RegionPingThreaded, 0, "RegionPing_" + this.region.Code + "_" + this.region.Cluster);
            #endif

            return(true);
        }
Esempio n. 3
0
    public static void StartFallbackSendAckThread()
    {
            #if !UNITY_WEBGL
        if (sendThreadShouldRun)
        {
            return;
        }

        sendThreadShouldRun = true;
        SupportClassPun.StartBackgroundCalls(FallbackSendAckThread);   // thread will call this every 100ms until method returns false
            #endif
    }
Esempio n. 4
0
        /// <summary>
        /// Connects this client to the Photon Chat Cloud service, which will also authenticate the user (and set a UserId).
        /// </summary>
        /// <param name="appId">Get your Photon Chat AppId from the <a href="https://www.photonengine.com/en/Chat/Dashboard">Dashboard</a>.</param>
        /// <param name="appVersion">Any version string you make up. Used to separate users and variants of your clients, which might be incompatible.</param>
        /// <param name="authValues">Values for authentication. You can leave this null, if you set a UserId before. If you set authValues, they will override any UserId set before.</param>
        /// <returns></returns>
        public bool Connect(string appId, string appVersion, AuthenticationValues authValues)
        {
            this.chatPeer.TimePingInterval = 3000;
            this.DisconnectedCause         = ChatDisconnectCause.None;

            if (authValues != null)
            {
                this.AuthValues = authValues;
                if (string.IsNullOrEmpty(this.AuthValues.UserId))
                {
                    if (this.DebugOut >= DebugLevel.ERROR)
                    {
                        this.listener.DebugReturn(DebugLevel.ERROR, "Connect failed: no UserId specified in authentication values.");
                    }
                    return(false);
                }
            }
            else
            {
                if (this.DebugOut >= DebugLevel.ERROR)
                {
                    this.listener.DebugReturn(DebugLevel.ERROR, "Connect failed: no authentication values specified");
                }
                return(false);
            }
            this.AppId           = appId;
            this.AppVersion      = appVersion;
            this.didAuthenticate = false;
            this.chatPeer.QuickResendAttempts = 2;
            this.chatPeer.SentCountAllowance  = 7;


            // clean all channels
            this.PublicChannels.Clear();
            this.PrivateChannels.Clear();
            this.PublicChannelsUnsubscribing.Clear();

            this.NameServerAddress = this.chatPeer.NameServerAddress;
            bool isConnecting = this.chatPeer.Connect();

            if (isConnecting)
            {
                this.State = ChatState.ConnectingToNameServer;
            }

            if (this.UseBackgroundWorkerForSending)
            {
                SupportClass.StartBackgroundCalls(this.SendOutgoingInBackground, this.msDeltaForServiceCalls, "ChatClient Service Thread");
            }

            return(isConnecting);
        }
Esempio n. 5
0
 public static byte CallInBackground(Func <bool> myThread, int millisecondsInterval = 100, string taskName = "")
 {
     return(SupportClass.StartBackgroundCalls(myThread, millisecondsInterval, null));
 }