Linux中国  设为主页
 收藏本站
 
当前位置: > 首页 ->编程语言 ->ASP.NET ->使用C#与NNTP服务器交互!
  相关分类: 
ASP
ViualBasic
UML / Rational Rose
PHP4/PHP5
Perl
JAVA/JSP教程
Delphi
ColdFusion
CGI
C/C++
ASP.NET
XML
  站内搜索: 
热门文章排行
热门文章排行 C#编写的windows计算器-源代码(06-04)
C# 操作文件(06-04)
c#操作word表格(06-04)
使用C#在进度条中显示复制文件的进度(06-04)
C# GridView 排序及分页(06-04)
精采文章排行
精采文章排行 用C#实现FTP搜索引擎(06-04)
对C# 2.0中匿名方法的怀疑分析(06-04)
在C#中利用DirectX实现声音播放(06-04)
使用C#在进度条中显示复制文件的进度(06-04)
C#中利用Markup Service实现HTML解析(06-04)
  ·对C# 2.0中匿名方法的怀疑分析·在C#中利用DirectX实现声音播放·使用C#在进度条中显示复制文件的进度·C#中利用Markup Service实现HTML解析为DO·c#操作word表格·C#代码操作IIS之虚拟目录·如何使用C#在发送往client的内容上加js代·[C#]解决读写包含汉字的txt文件时乱码的·C#实现根据域名查询ip实例

使用C#与NNTP服务器交互!

作者:Webmaster   来源:Linuxdby.com   点击:   日期:2007-06-04 [收藏] [投稿]

  IE是否经常中毒?推荐您

using System;
using System.Text;
using System.Net;
using System.IO;
using System.Net.Sockets;
using System.Collections;
using System.Diagnostics;

namespace NntpTools {
 /// <summary>
 /// Class1 的摘要说明。
 /// </summary>
 class Debug {
  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main(string[] args) {
   NNTPClass nc=new NNTPClass();
   nc.Connect("msnews.microsoft.com");
   ArrayList grouplist=nc.GetNewsgroups();
   for(int i=0;i<grouplist.Count;i++){
    Console.WriteLine(grouplist[i].ToString());
   }
   ArrayList cardlist=nc.GetNews("microsoft.public.cn.dotnet.framework");
   Console.WriteLine("=============================================================");
   StreamWriter sw=File.CreateText("c:\\news.txt");
   for(int i=0;i<cardlist.Count;i++){
    Console.WriteLine(cardlist[i].ToString());
    sw.WriteLine(cardlist[i].ToString());
    sw.WriteLine("=============================================================");
   }
   sw.Flush();
   sw.Close();
   nc.Disconnect();
  
   Console.ReadLine();
  }
 }

 class NNTPClass:System.Net.Sockets.TcpClient{
  public void Connect(string server){
   string response;

 

   Connect(server, 119);

   response = Response();

   if (response.Substring( 0, 3) != "200") {

    throw new Exception(response);

   }
  

  }

  public void Disconnect() {

   string message;

   string response;

 

   message = "QUIT\r\n";

   Write(message);

   response = Response();

   if (response.Substring( 0, 3) != "205") {

    throw new Exception(response);

   }

  }
  public ArrayList GetNewsgroups() {

   string message;

   string response;

 

   ArrayList retval = new ArrayList();

 

   message = "LIST\r\n";

   Write(message);

   response = Response();

   if (response.Substring( 0, 3) != "215") {

    throw new Exception(response);

   }

 

   while (true) {

    response = Response();

    if (response == ".\r\n" ||

     response == ".\n") {

     return retval;

    }

    else {

     char[] seps = { ' ' };

     string[] values = response.Split(seps);

     retval.Add(values[0]);

     continue;

    }

   }

  }
  public void Post(string newsgroup, string subject, string from,

   string content) {

   string message;

   string response;

 

   message = "POST " + newsgroup + "\r\n";

   Write(message);

   response = Response();

   if (response.Substring( 0, 3) != "340") {

    throw new Exception(response);

   }

 

   message = "From: " + from + "\r\n"

    + "Newsgroups: " + newsgroup + "\r\n"

    + "Subject: " + subject + "\r\n\r\n"

    + content + "\r\n.\r\n";

   Write(message);

   response = Response();

   if (response.Substring( 0, 3) != "240") {

    throw new Exception(response);

   }

  }


  public ArrayList GetNews(string newsgroup) {

   string message;

   string response;

 

   ArrayList retval = new ArrayList();

 

   message = "GROUP " + newsgroup + "\r\n";

   Write(message);

   response = Response();

   if (response.Substring( 0, 3) != "211") {

    throw new Exception(response);

   }

 

   char[] seps = { ' ' };

   string[] values = response.Split(seps);

 

   long start = Int32.Parse(values[2]);



 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<

上一页12 下一页

上一篇:用C#生成中文汉字验证码的基本原理   下一篇:C#实现根据域名查询ip实例
文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论

   相关文章:
·用C#实现FTP搜索引擎

   文章评论:(1条)
  
 请留名: 匿名评论   点击查看所有评论 论坛讨论
 

 声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。