Ejemplo n.º 1
0
        /// <summary>
        /// Start the server.
        /// </summary>
        /// <returns><c>true</c> if successful, otherwise <c>false</c>.</returns>
        public bool Start()
        {
            if (_processConnectionThread)
            {
                return(false);
            }

            _processConnectionThread = true;

            try
            {
                _messageQueue.ClearQueue();
                _messageQueue.Start();
            }
            catch
            {
                _processConnectionThread = false;

                throw;
            }

            try
            {
                _serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                _serverSocket.Bind(_localEndPoint);
                _serverSocket.Listen(SocketBacklog);
            }
            catch
            {
                _processConnectionThread = false;
                _serverSocket            = null;

                throw;
            }

            try
            {
                _clientManagers = new List <ClientManager>();

                _connectionThread              = new Thread(ConnectionThread);
                _connectionThread.Name         = "IrssComms.Server.ConnectionThread";
                _connectionThread.IsBackground = true;
                _connectionThread.Start();
            }
            catch
            {
                _processConnectionThread = false;
                _serverSocket            = null;
                _clientManagers          = null;
                _connectionThread        = null;

                throw;
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Start the client communications.
        /// </summary>
        /// <returns><c>true</c> if successful, otherwise <c>false</c>.</returns>
        public bool Start()
        {
            if (_processConnectionThread)
            {
                return(false);
            }

            _processConnectionThread = true;
            _connected = false;

            try
            {
                _messageQueue.ClearQueue();
                _messageQueue.Start();
            }
            catch
            {
                _processConnectionThread = false;

                throw;
            }

            try
            {
                Thread connectionThread = new Thread(ConnectionThread);
                connectionThread.Name         = "IrssComms.Client.ConnectionThread";
                connectionThread.IsBackground = true;
                connectionThread.Start();
            }
            catch
            {
                _processConnectionThread = false;
                _messageQueue.Stop();

                throw;
            }

            return(true);
        }