Example #1
0
        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);
            }
        }
Example #2
0
        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;
            }
        }
Example #3
0
        public sealed override void Disconnect(NetworkDisconnectReason reason)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(nameof(UdpClientEntity));
            }

            if (IsConnected)
            {
                _client?.Close();
            }
            if (!_disconnectNotified)
            {
                _disconnectNotified = true;
                OnDisconnected(reason);
            }
        }
Example #4
0
        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);
            }
        }
Example #5
0
        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);
            }
        }
Example #6
0
 protected virtual void OnClosed(NetworkDisconnectReason reason)
 {
 }
Example #7
0
 public abstract void Close(NetworkDisconnectReason reason);
Example #8
0
 public abstract void Disconnect(NetworkDisconnectReason reason);
Example #9
0
 protected virtual void OnClientDisconnected(TcpConnectionEntity connection, NetworkDisconnectReason reason)
 {
 }