/// <summary>
        /// Protocol negotiation finished successfully.
        /// </summary>
        private void OnNegotiationDataReceived(NegotiationData data)
        {
            // Find out what supported protocol the server speak
            int protocolIdx = -1;
            for (int i = 0; i < ClientProtocols.Length && protocolIdx == -1; ++i)
                if (data.ProtocolVersion == ClientProtocols[i])
                    protocolIdx = i;

            // No supported protocol found? Try using the latest one.
            if (protocolIdx == -1)
            {
                protocolIdx = (byte)ProtocolVersions.Protocol_2_2;
                HTTPManager.Logger.Warning("SignalR Connection", "Unknown protocol version: " + data.ProtocolVersion);
            }

            this.Protocol = (ProtocolVersions)protocolIdx;

#if !BESTHTTP_DISABLE_WEBSOCKET
            if (data.TryWebSockets)
            {
                Transport = new WebSocketTransport(this);

                #if !BESTHTTP_DISABLE_SERVERSENT_EVENTS
                    NextProtocolToTry = SupportedProtocols.ServerSentEvents;
                #else
                    NextProtocolToTry = SupportedProtocols.HTTP;
                #endif
            }
            else
#endif
            {
                #if !BESTHTTP_DISABLE_SERVERSENT_EVENTS
                    Transport = new ServerSentEventsTransport(this);

                    // Long-Poll
                    NextProtocolToTry = SupportedProtocols.HTTP;
                #else

                    Transport = new PollingTransport(this);

                    NextProtocolToTry = SupportedProtocols.Unknown;
                #endif
            }

            this.State = ConnectionStates.Connecting;
            TransportConnectionStartedAt = DateTime.UtcNow;

            Transport.Connect();
        }
예제 #2
0
        /// <summary>
        /// Protocol negotiation finished successfully.
        /// </summary>
        private void OnNegotiationDataReceived(NegotiationData data)
        {
#if !BESTHTTP_DISABLE_WEBSOCKET
            if (data.TryWebSockets)
            {
                Transport = new WebSocketTransport(this);

                #if !BESTHTTP_DISABLE_SERVERSENT_EVENTS
                    NextProtocolToTry = SupportedProtocols.ServerSentEvents;
                #else
                    NextProtocolToTry = SupportedProtocols.HTTP;
                #endif
            }
            else
#endif
            {
                #if !BESTHTTP_DISABLE_SERVERSENT_EVENTS
                    Transport = new ServerSentEventsTransport(this);

                    // Long-Poll
                    NextProtocolToTry = SupportedProtocols.HTTP;
                #else

                    Transport = new PollingTransport(this);

                    NextProtocolToTry = SupportedProtocols.Unknown;
                #endif
            }

            this.State = ConnectionStates.Connecting;
            TransportConnectionStartedAt = DateTime.UtcNow;

            Transport.Connect();
        }
예제 #3
0
        /// <summary>
        /// Protocol negotiation finished successfully.
        /// </summary>
        private void OnNegotiationDataReceived(NegotiationData data)
        {
            if (data.TryWebSockets)
            {
                Transport = new WebSocketTransport(this);

                NextProtocolToTry = SupportedProtocols.ServerSentEvents;
            }
            else
            {
                Transport = new ServerSentEventsTransport(this);

                // Long-Poll
                NextProtocolToTry = SupportedProtocols.HTTP;
            }

            this.State = ConnectionStates.Connecting;
            TransportConnectionStartedAt = DateTime.UtcNow;

            Transport.Connect();
        }