?? nntptest.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 + -