Inheritance: IDisposable
Exemple #1
0
        public void Start(int serverPort, int p2pServicePort, bool usingIPv6)
        {
            ThrowIfDisposed();

            if (_isServerRunning)
            {
                return;
            }

            if (!Connection.TcpPortIsAvailable(serverPort))
            {
                throw new ArgumentException("port not available", "serverPort");
            }

            _p2pService  = new P2PService(p2pServicePort, usingIPv6);
            _systemTimer = new Timer(OnTimer, null, SystemTimerInterval, -1);

            var address = usingIPv6 ? IPAddress.IPv6Any : IPAddress.Any;

            _listener             = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            _listener.LingerState = new LingerOption(false, 0);
            _listener.Bind(new IPEndPoint(address, serverPort));
            _listener.Listen(ListenConnections);
            _listener.BeginAccept(OnAccept, null);

            _isServerRunning = true;
        }
        private void StartImpl(IPAddress address)
        {
            _systemTimer = new Timer(OnTimer, null, SystemTimerInterval, -1);
            _p2pService  = new P2PService(address, _p2pServicePort, _api, _logger);

            _listener             = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            _listener.LingerState = new LingerOption(false, 0);
            _listener.Bind(new IPEndPoint(address, _port));
            _listener.Listen(ListenConnections);
            _listener.BeginAccept(OnAccept, null);
        }
Exemple #3
0
        public void CloseConnection(string id)
        {
            P2PService.RemoveEndPoint(id);
            lock (_connections)
            {
                var connection = GetConnection(id, true);
                if (connection == null)
                {
                    return;
                }

                _connections.Remove(id);
                connection.Dispose();
            }
        }
Exemple #4
0
        private void DisposeManagedResources()
        {
            _isServerRunning = false;

            if (_requestQueue != null)
            {
                _requestQueue.Dispose();
            }

            lock (_timerSync)
            {
                if (_systemTimer != null)
                {
                    _systemTimer.Dispose();
                }

                _systemTimer = null;
            }

            lock (_connections)
            {
                foreach (var connection in _connections.Values)
                {
                    connection.Dispose();
                }

                _connections.Clear();
            }

            if (_listener != null)
            {
                _listener.Dispose();
                _listener = null;
            }

            if (_p2pService != null)
            {
                _p2pService.Dispose();
                _p2pService = null;
            }
        }
Exemple #5
0
        private void DisposeManagedResources()
        {
            isServerRunning = false;

            if (requestQueue != null)
            {
                requestQueue.Dispose();
            }

            lock (timerSync)
            {
                if (systemTimer != null)
                {
                    systemTimer.Dispose();
                }

                systemTimer = null;
            }

            lock (connections)
            {
                foreach (var connection in connections.Values)
                {
                    connection.Dispose();
                }

                connections.Clear();
            }

            if (listener != null)
            {
                listener.Dispose();
                listener = null;
            }

            if (p2pService != null)
            {
                p2pService.Dispose();
                p2pService = null;
            }
        }
Exemple #6
0
        private void DisposeManagedResources()
        {
            isServerRunning = false;

              if (requestQueue != null)
            requestQueue.Dispose();

              lock (timerSync)
              {
            if (systemTimer != null)
              systemTimer.Dispose();

            systemTimer = null;
              }

              lock (connections)
              {
            foreach (var connection in connections.Values)
              connection.Dispose();

            connections.Clear();
              }

              if (listener != null)
              {
            listener.Dispose();
            listener = null;
              }

              if (p2pService != null)
              {
            p2pService.Dispose();
            p2pService = null;
              }
        }
Exemple #7
0
        public void Start(int serverPort, int p2pServicePort, bool usingIPv6)
        {
            ThrowIfDisposed();

              if (isServerRunning)
            return;

              if (!Connection.TcpPortIsAvailable(serverPort))
            throw new ArgumentException("port not available", "serverPort");

              p2pService = new P2PService(p2pServicePort, usingIPv6);
              systemTimer = new Timer(TimerCallback, null, SystemTimerInterval, -1);

              var address = usingIPv6 ? IPAddress.IPv6Any : IPAddress.Any;

              listener = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
              listener.LingerState = new LingerOption(false, 0);
              listener.Bind(new IPEndPoint(address, serverPort));
              listener.Listen(ListenConnections);
              listener.BeginAccept(AcceptCallback, null);

              isServerRunning = true;
        }