boost代码service
1 #include <iostream> 2 #include <boost/asio.hpp> 4 using namespace std; 5 using boost::asio::ip::tcp; 7 8 int main () 9 { 10 try 11 { 12 // 13 boost::asio::io_service ioservice; 14 tcp::acceptor accept(ioservice,tcp::endpoint(tcp::v4(),6688)); 15 while(true) 16 { 17 tcp::socket sock(ioservice); 18 accept.accept(sock); 19 cout<<sock.remote_endpoint().address()<<endl; 20 sock.write_some(boost::asio::buffer("hello pig")); 21 } 22 } 23 catch(exception &e) 24 { 25 cerr<<e.what()<<endl; 26 } 27 28 return 0; 29 }