Пример #1
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();
        }
Пример #2
0
        /// <summary>
        /// It's the real Start implementation. It will start the negotiation
        /// </summary>
        private void StartImpl()
        {
            this.State = ConnectionStates.Negotiating;

            NegotiationResult            = new NegotiationData(this);
            NegotiationResult.OnReceived = OnNegotiationDataReceived;
            NegotiationResult.OnError    = OnNegotiationError;
            NegotiationResult.Start();
        }
Пример #3
0
        /// <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();
        }
Пример #4
0
 /// <summary>
 /// Protocol negotiation failed.
 /// </summary>
 private void OnNegotiationError(NegotiationData data, string error)
 {
     (this as IConnection).Error(error);
 }
Пример #5
0
 /// <summary>
 /// Protocol negotiation failed.
 /// </summary>
 private void OnNegotiationError(NegotiationData data, string error)
 {
     (this as IConnection).Error(error);
 }
Пример #6
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();
        }
Пример #7
0
        /// <summary>
        /// It's the real Start implementation. It will start the negotiation
        /// </summary>
        private void StartImpl()
        {
            this.State = ConnectionStates.Negotiating;

            NegotiationResult = new NegotiationData(this);
            NegotiationResult.OnReceived = OnNegotiationDataReceived;
            NegotiationResult.OnError = OnNegotiationError;
            NegotiationResult.Start();
        }
        /// <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();
        }
Пример #9
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();
        }