Example #1
0
 public Task StartReconnection()
 {
     reconnectCancellationSource = new CancellationTokenSource();
     return(Task.Factory.StartNew(async() =>
     {
         reconnectCancellationSource.Token.ThrowIfCancellationRequested();
         while (true)
         {
             if (reconnectCancellationSource.Token.IsCancellationRequested)
             {
                 reconnectCancellationSource.Token.ThrowIfCancellationRequested();
             }
             if (ConnectionChallengeFunction == null)
             {
                 throw new ConfigurationException("Unsetted challenge function for reconnection.");
             }
             if (!await ConnectionChallengeFunction(this))
             {
                 StoptListener();
                 ConnectionFailure?.Invoke(this, DateTime.UtcNow);
                 await ProtocolStream.Reconnect();
                 startListener();
             }
             await Task.Delay(ConnectionDelay);
         }
     }, reconnectCancellationSource.Token));
 }
Example #2
0
 /// <summary>
 ///		Desconecta del servidor
 /// </summary>
 internal void Disconnect()
 {
     if (ProtocolStream != null)
     {
         // Libera el stream de datos
         try
         {
             ProtocolStream.Dispose();
         }
         catch (System.Net.Sockets.SocketException) { }
         catch (System.IO.IOException) { }
         // Libera el objeto
         ProtocolStream = null;
     }
 }
Example #3
0
 /// <summary>
 /// Disposes the transport.
 /// </summary>
 internal void Disconnect()
 {
     if (ProtocolStream != null)
     {
         try
         {
             ProtocolStream.Dispose();
         }
         catch (SocketException)
         {
         }
         catch (IOException)
         {
         }
         ProtocolStream = null;
     }
 }