同步服务端:
boost::timer tm; io_service is; ip::tcp::acceptor acceptor(is, ip::tcp::endpoint(ip::tcp::v4(), 8000)); for(;;) { ip::tcp::socket so(is); acceptor.accept(so); char buf[501]; error_code ec; so.read_some(buffer(buf), ec); buf[500] = '\0'; cout << buf << endl; cout << "all time:"<<tm.elapsed() << endl; }同步客户端:
io_service is;
ip::tcp::socket socket(is);
ip::tcp::endpoint ep(ip::address_v4::from_string("192.168.3.33"), 8000);
socket.connect(ep);
error_code ec;
char buff[500];
memset(buff, '9', 500);
socket.write_some(buffer(buff, 500), ec);
return NULL;
异步服务端: