Exemplo n.º 1
0
        private bool TryFallbackTransport()
        {
            if (State == ConnectionStates.Connecting)
            {
                if (BufferedMessages != null)
                {
                    BufferedMessages.Clear();
                }
                Transport.Stop();
                Transport = null;
                switch (NextProtocolToTry)
                {
                case SupportedProtocols.ServerSentEvents:
                    Transport         = new ServerSentEventsTransport(this);
                    NextProtocolToTry = SupportedProtocols.HTTP;
                    break;

                case SupportedProtocols.HTTP:
                    Transport         = new PollingTransport(this);
                    NextProtocolToTry = SupportedProtocols.Unknown;
                    break;

                case SupportedProtocols.Unknown:
                    return(false);
                }
                TransportConnectionStartedAt = DateTime.UtcNow;
                Transport.Connect();
                if (PingRequest != null)
                {
                    PingRequest.Abort();
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Try to fall back to next transport. If no more transport to try, it will return false.
        /// </summary>
        private bool TryFallbackTransport()
        {
            if (this.State == ConnectionStates.Connecting)
            {
                if (BufferedMessages != null)
                {
                    BufferedMessages.Clear();
                }

                // stop the current transport
                Transport.Stop();
                Transport = null;

                switch (NextProtocolToTry)
                {
#if !BESTHTTP_DISABLE_WEBSOCKET
                case SupportedProtocols.WebSocket:
                    Transport = new WebSocketTransport(this);
                    break;
#endif

#if !BESTHTTP_DISABLE_SERVERSENT_EVENTS
                case SupportedProtocols.ServerSentEvents:
                    Transport         = new ServerSentEventsTransport(this);
                    NextProtocolToTry = SupportedProtocols.HTTP;
                    break;
#endif

                case SupportedProtocols.HTTP:
                    Transport         = new PollingTransport(this);
                    NextProtocolToTry = SupportedProtocols.Unknown;
                    break;

                case SupportedProtocols.Unknown:
                    return(false);
                }

                TransportConnectionStartedAt = DateTime.UtcNow;

                Transport.Connect();

                if (PingRequest != null)
                {
                    PingRequest.Abort();
                }

                return(true);
            }

            return(false);
        }