Beispiel #1
0
        private void OnNegotiationDataReceived(NegotiationData data)
        {
            int num = -1;

            for (int i = 0; i < ClientProtocols.Length; i++)
            {
                if (num != -1)
                {
                    break;
                }
                if (data.ProtocolVersion == ClientProtocols[i])
                {
                    num = i;
                }
            }
            if (num == -1)
            {
                num = 2;
                HTTPManager.Logger.Warning("SignalR Connection", "Unknown protocol version: " + data.ProtocolVersion);
            }
            Protocol = (ProtocolVersions)num;
            if (data.TryWebSockets)
            {
                Transport         = new WebSocketTransport(this);
                NextProtocolToTry = SupportedProtocols.ServerSentEvents;
            }
            else
            {
                Transport         = new ServerSentEventsTransport(this);
                NextProtocolToTry = SupportedProtocols.HTTP;
            }
            State = ConnectionStates.Connecting;
            TransportConnectionStartedAt = DateTime.UtcNow;
            Transport.Connect();
        }
Beispiel #2
0
 private void StartImpl()
 {
     State                        = ConnectionStates.Negotiating;
     NegotiationResult            = new NegotiationData(this);
     NegotiationResult.OnReceived = OnNegotiationDataReceived;
     NegotiationResult.OnError    = OnNegotiationError;
     NegotiationResult.Start();
 }
Beispiel #3
0
        private void OnNegotiationRequestFinished(HTTPRequest req, HTTPResponse resp)
        {
            NegotiationRequest = null;
            switch (req.State)
            {
            case HTTPRequestStates.Finished:
                if (resp.IsSuccess)
                {
                    HTTPManager.Logger.Information("NegotiationData", "Negotiation data arrived: " + resp.DataAsText);
                    int num = resp.DataAsText.IndexOf("{");
                    if (num < 0)
                    {
                        RaiseOnError("Invalid negotiation text: " + resp.DataAsText);
                    }
                    else
                    {
                        NegotiationData negotiationData = Parse(resp.DataAsText.Substring(num));
                        if (negotiationData == null)
                        {
                            RaiseOnError("Parsing Negotiation data failed: " + resp.DataAsText);
                        }
                        else if (OnReceived != null)
                        {
                            OnReceived(this);
                            OnReceived = null;
                        }
                    }
                }
                else
                {
                    RaiseOnError($"Negotiation request finished Successfully, but the server sent an error. Status Code: {resp.StatusCode}-{resp.Message} Message: {resp.DataAsText} Uri: {req.CurrentUri}");
                }
                break;

            case HTTPRequestStates.Error:
                RaiseOnError((req.Exception == null) ? string.Empty : (req.Exception.Message + " " + req.Exception.StackTrace));
                break;

            default:
                RaiseOnError(req.State.ToString());
                break;
            }
        }
Beispiel #4
0
 private void OnNegotiationError(NegotiationData data, string error)
 {
     ((IConnection)this).Error(error);
 }