public sealed override void Close(NetworkDisconnectReason reason) { if (IsDisposed) { throw new ObjectDisposedException(nameof(TcpServerEntity)); } if (IsRunning) { _socket?.Close(); } if (!_closeNotified) { TcpConnectionEntity[] entities; lock (_connections) { entities = _connections.Values.ToArray(); _connections.Clear(); } foreach (var connection in entities) { connection.Dispose(); } _closeNotified = true; OnClosed(reason); } }
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 sealed override void Disconnect(NetworkDisconnectReason reason) { if (IsDisposed) { throw new ObjectDisposedException(nameof(UdpClientEntity)); } if (IsConnected) { _client?.Close(); } if (!_disconnectNotified) { _disconnectNotified = true; OnDisconnected(reason); } }
public sealed override void Close(NetworkDisconnectReason reason) { if (IsDisposed) { throw new ObjectDisposedException(nameof(UdpServerEntity)); } if (IsInitialized) { _client?.Close(); _client = null; } if (!_closeNotified) { _connections.Clear(); _closeNotified = true; OnClosed(reason); } }
public sealed override void Disconnect(NetworkDisconnectReason reason) { if (IsDisposed) { throw new ObjectDisposedException(nameof(TcpClientEntity)); } if (IsConnected) { try { _socket?.Shutdown(SocketShutdown.Both); } catch { } _socket?.Disconnect(false); } if (!_disconnectNotified) { _reader.Clear(); _disconnectNotified = true; OnDisconnected(reason); } }
protected virtual void OnClosed(NetworkDisconnectReason reason) { }
public abstract void Close(NetworkDisconnectReason reason);
public abstract void Disconnect(NetworkDisconnectReason reason);
protected virtual void OnClientDisconnected(TcpConnectionEntity connection, NetworkDisconnectReason reason) { }