#include "socket.h" #include "tcpsocket.h" #include "resolver.h" #include "thread.h" #include "threadtest.h" using namespace n2nc ; int main(){ // std::string mys("127.0.0.1"); // std::string mys("::1"); // std::string myport("6099"); // net::Address *testaddr = new net::IP4Address(mys); // std::cerr << testaddr->toString(); // std::string mys3("195.210.91.83"); // n2nc::net::Address *ma = n2nc::net::Address::newAddress(mys2); // n2nc::net::Address *ma = sa->getAddress(); net::Socket *sock = new net::TcpSocket(AF_INET6); // net::Socket sockcpy = *sock ; net::SocketAddress *sa = net::Resolver::getSocketAddressByService("::1","6099",SOCK_STREAM,AF_INET6,false); std::cerr << "test: " << sa->getAddress()->toString() << std::endl ; sock->bind(*sa); ((net::TcpSocket*)(sock))->setListen(); std::cerr << "listening to: " << sa->toString() << std::endl ; sleep(2); n2nc::sync::Thread *tr = new ThreadTest(); tr->run(NULL); sleep(2); net::Socket *consock = ((net::TcpSocket*)sock)->accept(); // system("read"); // sa->toString(); // delete sa ; // sleep(5); int left = 3; char mybuf[100]; while(left--){ consock->recv(mybuf,100); std::cerr << mybuf << std::endl; sleep(1); } tr->terminate(); sleep(2); delete consock ; delete sock ; delete sa ; return EXIT_SUCCESS ; }