Example #1
0
        public void HandshakeWithServer()
        {
            connection.DataReceived     += DataReceived;
            connection.ConnectionFailed += ConnectionFailed;

            connection.Handshake();

            Assert.AreEqual(WaiterResults.Success, waiter.Wait(15));
        }
Example #2
0
        /// <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");
                }
            });
        }