Example #1
0
        void ChangeStatus(TcpConnectionStatus newStatus)
        {
            if (status == newStatus)
            {
                return;
            }

            status = newStatus;

            logger.Info($"{nameof(TcpClient)} status changed to {newStatus}");

            configuration.SynchronizeSafe(() => {
                ClientStatusChangedEventArgs args = new ClientStatusChangedEventArgs(newStatus);
                try
                {
                    OnStatusChanged(args);
                }
                catch (Exception ex)
                {
                    Logger.Error($"Unhandled exception on {this.GetType().Name}.{nameof(OnStatusChanged)}: {ex}");
                }
                try
                {
                    OnStatusChangedEvent?.Invoke(args);
                }
                catch (Exception ex)
                {
                    Logger.Error($"Unhandled exception on {this.GetType().Name}.{nameof(OnStatusChangedEvent)}: {ex}");
                }
            }, logger);
        }
Example #2
0
 private void OnConnectionClosed(ITcpConnection connection, SocketError socketError)
 {
     ConnectionStatus = TcpConnectionStatus.ConnectionClosed;
     _logger.InfoFormat("TCP connection closed: [remoteEndPoint:{0}, localEndPoint:{1}, connectionId:{2:B}, socketError:{3}].", connection.RemoteEndPoint, connection.LocalEndPoint, connection.ConnectionId, socketError);
     if (_eventListener != null)
     {
         _eventListener.OnConnectionClosed(connection, socketError);
     }
 }
Example #3
0
 private void OnConnectionEstablished(ITcpConnection connection)
 {
     ConnectionStatus = TcpConnectionStatus.ConnectionEstablished;
     _logger.InfoFormat("TCP connection established: [remoteEndPoint:{0}, localEndPoint:{1}, connectionId:{2:B}].", connection.RemoteEndPoint, connection.LocalEndPoint, connection.ConnectionId);
     _startWaitHandle.Set();
     if (_eventListener != null)
     {
         _eventListener.OnConnectionEstablished(connection);
     }
 }
Example #4
0
 public TcpClient(TcpConfigurationClient configuration) : base(configuration)
 {
     if (configuration == null)
     {
         throw new ArgumentNullException(nameof(configuration));
     }
     this.configuration = configuration;
     this.logger        = configuration.LogManager.GetLogger(nameof(TcpClient));
     this.logger.Meta.Add("kind", this.GetType().Name);
     status = TcpConnectionStatus.Disconnected;
 }
Example #5
0
 public RemotingServerNotConnectedException(IPEndPoint serverEndPoint, TcpConnectionStatus status)
     : base(string.Format("Remoting server is not connected, server address: {0}, connectionStatus: {1}. Please ensure that you have started the remoting client and connected to the remoting server.", serverEndPoint, status))
 {
 }
Example #6
0
 private static void RespondToTcpConnection(Stream stream, JsonOperationContext context, string error, TcpConnectionStatus status)
 {
     using (var writer = new BlittableJsonTextWriter(context, stream))
     {
         writer.WriteStartObject();
         writer.WritePropertyName(nameof(TcpConnectionHeaderResponse.Status));
         writer.WriteString(status.ToString());
         if (error != null)
         {
             writer.WriteComma();
             writer.WritePropertyName(nameof(TcpConnectionHeaderResponse.Message));
             writer.WriteString(error);
         }
         writer.WriteEndObject();
         writer.Flush();
     }
 }
 internal ClientStatusChangedEventArgs(TcpConnectionStatus newStatus)
 {
     this.Status = newStatus;
 }
 public RemotingServerNotConnectedException(IPEndPoint serverEndPoint, TcpConnectionStatus status)
     : base(string.Format("Remoting server is not connected, server address: {0}, connectionStatus: {1}. Please ensure that you have started the remoting client and connected to the remoting server.", serverEndPoint, status))
 {
 }