internal AsyncServer(ErrorRecievedHandler err, DataRecievedHandler dataCallback, ClientDisconnectHandler clientCallback,
     ConnectionRecievedHandler connectionCallback)
 {
     localIP = GetLocalIP();
     encoding = Encoding.Default;
     errorHandler = err;
     this.dataCallback = dataCallback;
     connectionDropCallback = clientCallback;
     this.connectionCallback = connectionCallback;
 }
Exemple #2
0
 internal AsyncServer(ErrorRecievedHandler err, DataRecievedHandler dataCallback, ClientDisconnectHandler clientCallback,
                      ConnectionRecievedHandler connectionCallback)
 {
     localIP                 = GetLocalIP();
     encoding                = Encoding.Default;
     errorHandler            = err;
     this.dataCallback       = dataCallback;
     connectionDropCallback  = clientCallback;
     this.connectionCallback = connectionCallback;
 }
        /// <summary>
        /// Gets the raw body for the specified article
        /// </summary>
        /// <param name="article">message id</param>
        /// <param name="action"></param>
        /// <returns>String containing body of article</returns>
        public String GetArticleBody(String article, DataRecievedHandler action)
        {
            if (String.IsNullOrEmpty(article))
            {
                throw new ArgumentNullException("article");
            }

            StringBuilder articleBuilder = new StringBuilder();

            Write("BODY <{0}>", article);

            String response = this.Response();

            if (response.Substring(0, 3) != "222")
            {
                throw new NntpException(response, 222, Int32.Parse(response.Substring(0, 3)));
            }

            UInt32 i = 0;

            while (true)
            {
                response = Response();

                if (DataRecieved != null || action != null)
                {
                    byte[] bytes = Encoding.ASCII.GetBytes(response);

                    if (DataRecieved != null)
                    {
                        DataRecieved(this, new NntpEventArgs(bytes, i));
                    }

                    if (action != null)
                    {
                        action(bytes, i);
                    }

                    i++;
                }

                if (response == ".\r\n" || response == ".\n")
                {
                    break;
                }

                articleBuilder.Append(response);
            }

            String articleName = articleBuilder.ToString();

            return(articleName);
        }
        /// <summary>
        /// Gets the raw body for the specified article
        /// </summary>
        /// <param name="article">message id</param>
        /// <param name="action"></param>
        /// <returns>String containing body of article</returns>
        public String GetArticleBody(String article, DataRecievedHandler action)
        {
            if (String.IsNullOrEmpty(article)) throw new ArgumentNullException("article");

            StringBuilder articleBuilder = new StringBuilder();

            Write("BODY <{0}>", article);

            String response = this.Response();

            if (response.Substring(0, 3) != "222")
            {
                throw new NntpException(response, 222, Int32.Parse(response.Substring(0, 3)));
            }

            UInt32 i = 0;
            while (true)
            {
                response = Response();

                if (DataRecieved != null || action != null)
                {
                    byte[] bytes = Encoding.ASCII.GetBytes(response);

                    if (DataRecieved != null)
                    {
                        DataRecieved(this, new NntpEventArgs(bytes, i));
                    }

                    if (action != null)
                    {
                        action(bytes, i);
                    }

                    i++;
                }

                if (response == ".\r\n" || response == ".\n")
                {
                    break;
                }

                articleBuilder.Append(response);
            }

            String articleName = articleBuilder.ToString();

            return articleName;
        }