public void Disconnect(NetworkDisconnectReason reason) { if (IsDisposed) { throw new ObjectDisposedException(nameof(TcpConnectionEntity)); } if (IsConnected) { try { _socket.Shutdown(SocketShutdown.Both); } catch { } _socket?.Disconnect(false); _reader?.Dispose(); } if (!_disconnectionNotified) { _disconnectionNotified = true; Disconnected?.Invoke(reason); _buffer = null; _socket = null; Disconnected = null; } }
public void Dispose() { if (!IsDisposed) { BeforeDispose(); Disconnect(NetworkDisconnectReason.Manual); _reader.Dispose(); _socket?.Dispose(); IsDisposed = true; } }