Exemple #1
0
 /// <summary>
 ///     Connects to server.
 /// </summary>
 public void Connect()
 {
     WireProtocol.Reset();
     _communicationChannel = CreateCommunicationChannel();
     _communicationChannel.WireProtocol     = WireProtocol;
     _communicationChannel.Disconnected    += CommunicationChannel_Disconnected;
     _communicationChannel.MessageReceived += CommunicationChannel_MessageReceived;
     _communicationChannel.MessageSent     += CommunicationChannel_MessageSent;
     _communicationChannel.Start();
     _pingTimer.Start();
     OnConnected();
 }
        /// <summary>
        ///     Creates a new ClientReConnecter object.
        ///     It is not needed to start ClientReConnecter since it automatically
        ///     starts when the client disconnected.
        /// </summary>
        /// <param name="client">Reference to client object</param>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if client is null.</exception>
        public ClientReConnecter(IConnectableClient client)
        {
            if (client == null) {
                throw new ArgumentNullException("client");
            }

            _client = client;
            _client.Disconnected += Client_Disconnected;
            _reconnectTimer = new SimpleConnectionTimer(20000);
            _reconnectTimer.Elapsed += ReconnectTimer_Elapsed;
            _reconnectTimer.Start();
        }
        /// <summary>
        ///     Creates a new ClientReConnecter object.
        ///     It is not needed to start ClientReConnecter since it automatically
        ///     starts when the client disconnected.
        /// </summary>
        /// <param name="client">Reference to client object</param>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if client is null.</exception>
        public ClientReConnecter(IConnectableClient client)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            _client = client;
            _client.Disconnected    += Client_Disconnected;
            _reconnectTimer          = new SimpleConnectionTimer(20000);
            _reconnectTimer.Elapsed += ReconnectTimer_Elapsed;
            _reconnectTimer.Start();
        }
 /// <summary>
 ///     Handles Disconnected event of _client object.
 /// </summary>
 /// <param name="sender">Source of the event</param>
 /// <param name="e">Event arguments</param>
 private void Client_Disconnected(object sender, EventArgs e)
 {
     _reconnectTimer.Start();
 }