Beispiel #1
0
        public override async Task ConnectAsync()
        {
            await base.ConnectAsync();

            Uri uri = UriConverter.GetServerUri(false, ServerUri, EIO, Options.Path, Options.Query);
            var req = new HttpRequestMessage(HttpMethod.Get, uri);

            if (Options.ExtraHeaders != null)
            {
                foreach (var item in Options.ExtraHeaders)
                {
                    req.Headers.Add(item.Key, item.Value);
                }
            }

            if (EIO == 3)
            {
                _httpTransport = new HttpEio3Transport(HttpClient);
            }
            else
            {
                _httpTransport = new HttpEio4Transport(HttpClient);
            }

            _httpTransport.OnTextReceived   = OnTextReceived;
            _httpTransport.OnBinaryReceived = OnBinaryReceived;

            await _httpTransport.SendAsync(req, new CancellationTokenSource(Options.ConnectionTimeout).Token).ConfigureAwait(false);

            if (_pollingTokenSource != null)
            {
                _pollingTokenSource.Cancel();
            }
            _pollingTokenSource = new CancellationTokenSource();

            StartPolling(_pollingTokenSource.Token);
        }