public void TryToStartLongPollingRequestWithoutDefineLongPollingDataSource()
        {
            var httpDataSource = new HttpDataSource("http://www.google.pl");
            var connection     = new BayeuxConnection(httpDataSource, null);

            connection.StartLongPolling(new HandshakeRequest(BayeuxConnectionTypes.LongPolling, null, null));
        }
        public void CheckIfByDefaultLongPollingConnectionIsNotCreated()
        {
            var httpDataSource = new HttpDataSource("http://www.google.pl");
            var connection     = new BayeuxConnection(httpDataSource); // <--- different constructor used, comparing to CreateBayeuxConnectionWithoutLongPolling() test

            connection.LongPollingTimeout = 100;

            Assert.IsFalse(connection.IsLongPolling);
            Assert.AreEqual(0, connection.LongPollingTimeout);
        }
        public void CreateBayeuxConnectionWithoutLongPolling()
        {
            var httpDataSource = new HttpDataSource("http://www.google.pl");
            var connection     = new BayeuxConnection(httpDataSource, null);

            connection.LongPollingTimeout = 100;

            Assert.IsFalse(connection.IsLongPolling);
            Assert.AreEqual(0, connection.LongPollingTimeout);
        }
        public void InitializeLongPollingConnection()
        {
            var       httpDataSource            = new HttpDataSource("http://www.google.pl");
            var       httpLongPollingDataSource = new HttpDataSource("http://www.google.pl/long");
            const int Timeout    = 150;
            var       connection = new BayeuxConnection(httpDataSource, httpLongPollingDataSource);

            connection.LongPollingTimeout = Timeout;

            Assert.AreEqual(Timeout, connection.LongPollingTimeout);
        }
Exemple #5
0
        public void TestInit()
        {
            connection = new BayeuxConnection("http://192.168.2.179:8080/cometd/");
            connection.DataReceived     += LogDataReceived;
            connection.DataFailed       += LogDataFailed;
            connection.ConnectionFailed += LogConnectionFailed;
            connection.Timeout           = 2000;

            waiter = new AsyncWaiter();
            waiter.Reset();
        }
Exemple #6
0
        static async Task Main(string[] args)
        {
            var loggerFactory = new LoggerFactory();
            var streamingUri  = new Uri("<uri>");
            var observer      = Observer.Create <JObject>(OnNext, OnError);
            var clientOptions = new HttpLongPollingTransportOptions(() => new HttpClient(),
                                                                    streamingUri, observer);
            var connection = new BayeuxConnection(clientOptions, new ReconnectDelays(), loggerFactory);
            var cancellationTokenSource = new CancellationTokenSource();
            await connection.StartAsync(cancellationTokenSource.Token);

            var channels = new (string, FSharpValueOption <long>)[]
        /// <summary>
        /// Connects to the specified user channel
        /// Initializes a long polling connection and handshakes with the server
        /// Registers all the call back event handlers
        /// </summary>
        /// <param name="chan"> The channel to connect </param>
        public async void Connect(string chan)
        {
            await Task.Run(() =>
            {
                try
                {
                    if (_isConnected)
                    {
                        return;
                    }

                    _isConnected = true;

                    if (_channel.Equals(""))
                    {
                        _channel = "/messages/User_" + chan;
                    }

                    var httpDataSource            = new HttpDataSource(ConnectionUri, null, DefaultContentType);
                    var httpLongPollingDataSource = new HttpDataSource(ConnectionUri, null, DefaultContentType);
                    _connection = new BayeuxConnection(httpDataSource, httpLongPollingDataSource)
                    {
                        LongPollingTimeout = 30000
                    };

                    _connection.Connected         += connection_Connected;
                    _connection.Disconnected      += connection_Disconnected;
                    _connection.EventReceived     += LogChatEventReceived;
                    _connection.DataReceived      += LogDataReceived;
                    _connection.DataFailed        += LogDataFailed;
                    _connection.ConnectionFailed  += LogConnectionFailed;
                    _connection.LongPollingFailed += _connection_LongPollingFailed;

                    _connection.Handshake();
                }
                catch (Exception)
                {
                    Console.WriteLine("Faye Connect Error");
                }
            });
        }
Exemple #8
0
 public Task SetConnectionAsync(BayeuxConnection newConnection, CancellationToken cancellationToken)
 {
     currentConnection = newConnection;
     return(RequestSubscribeAsync(subscribedChannels.ToImmutableArray(), cancellationToken, throwIfNotConnected: false));
 }