使用C#与NNTP服务器交互!using System; namespace NntpTools { class NNTPClass:System.Net.Sockets.TcpClient{
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); } } 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; } } } 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); } }
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]); 上一篇:用C#生成中文汉字验证码的基本原理 下一篇:C#实现根据域名查询ip实例 更多相关文章
|
推荐文章
精彩文章
|