boost: tcp client sample

#include <boost/asio.hpp>
#include <iostream> using namespace std;
using namespace boost::asio; void client(io_service &ios)
{
try
{
cout << "client start." << endl; ip::tcp::socket sock(ios);
ip::tcp::endpoint ep(ip::address::from_string("127.0.0.1"),); sock.connect(ep); vector<char> str(,);
sock.read_some(buffer(str));
cout << "receive from " << sock.remote_endpoint().address();
cout << &str[] << endl;
}
catch (std::exception& e)
{
cout << e.what() << endl;
}
} void print(const boost::system::error_code&)
{
cout << "test wait..." << endl;
} int main()
{
io_service ios;
deadline_timer at(ios, boost::posix_time::seconds());
at.async_wait(print); cout << "it show before at exired" <<endl;
ios.run();
return ;
}
上一篇:【转】浅谈Nginx负载均衡与F5的区别


下一篇:Linux下设置python脚本文件为服务