Exemplo n.º 1
0
        public bool Connect(string server, int port)
        {
            if (string.IsNullOrEmpty(server))
            {
                throw new ArgumentNullException("server");
            }

            if (port <= 0)
            {
                throw new ArgumentOutOfRangeException("port");
            }

            if (Connected)
            {
                throw new InvalidOperationException("Client is already connected");
            }

            Server     = server;
            Port       = port;
            _lastError = "";

            try
            {
                _client.Connect(server, port);
            }
            catch (Exception ex)
            {
                _lastError = "Unable to Connect to Server\n" + ex.Message;
                return(false);
            }

            _lastActivity = DateTime.Now;

            return(true);
        }