⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nntptest.cc

📁 2007年机器人足球世界杯3D仿真组亚军
💻 CC
字号:
#include <iostream>#include "socket.hh"#include "timeval.hh"using namespace mvds;bool canRead(Socket _s){  fd_set read_set;  TimeVal tv(1,0);  int max_descr = _s + 1, res;  FD_ZERO(&read_set);  FD_SET(_s,&read_set);  res = select(max_descr,&read_set,0,0,tv);  return FD_ISSET(_s,&read_set);}void waitRead(Socket _s){  while (!canRead(_s)) {    std::cerr << "." << std::endl;  }}int main(){  Socket s(PF_INET,SOCK_STREAM,0);  SocketAddress sockaddr(1818,"europe.news.astraweb.com");  s.connect(sockaddr);  if (!s) {    std::cerr << "Error connecting to the server." << std::endl;    return 1;  }  waitRead(s);  char buf[512];  unsigned len = s.read(buf,512);  //  unsigned pos;  std::cout.write(buf,len);  if (buf[0] != '2') {    return 1;  }  std::string cmd;  cmd = "AUTHINFO USER vdsanden\r\n";  s.write(cmd.c_str(),cmd.length());  std::cout << "Sending: " << cmd << std::endl;  waitRead(s);  buf[0] = 0;  len = s.read(buf,512);  std::cout.write(buf,len);  if (buf[0] != '3') {    return 1;  }  cmd = "AUTHINFO PASS qMeDhZ39\r\n";  s.write(cmd.c_str(),cmd.length());  std::cout << "Sending: " << cmd << std::endl;  waitRead(s);  buf[0] = 0;  len = s.read(buf,512);  std::cout.write(buf,len);  if (buf[0] != '2') {    return 1;  }  cmd = "GROUP alt.binaries.tv\r\n";  s.write(cmd.c_str(),cmd.length());  std::cout << "Sending: " << cmd << std::endl;  waitRead(s);  buf[0] = 0;  len = s.read(buf,512);  std::cout.write(buf,len);  if (buf[0] != '2') {    return 1;  }  cmd = "ARTICLE <1130103296.58141,1@news.octanews.com>\r\n";  s.write(cmd.c_str(),cmd.length());  std::cout << "Sending: " << cmd << std::endl;  waitRead(s);  buf[0] = 0;  len = s.read(buf,512);  std::cout.write(buf,len);  if (buf[0] != '2') {    return 1;  }  while (s && (buf[0] != '.' || buf[1] == '.')) {    len = s.read(buf,512);    std::cout.write(buf,len);  }  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -