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); }
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); } }
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); } }
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; }
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)) { }
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; }