kevin55

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
#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"),6688);

        sock.connect(ep);

        vector<char> str(100,0);
        sock.read_some(buffer(str));
        cout << "receive from " << sock.remote_endpoint().address();
        cout << &str[0] << 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(5));
    at.async_wait(print);

    cout << "it show before at exired" <<endl;
    ios.run();
    return 0;
}

 

posted on 2014-07-15 23:39  kernel_main  阅读(1007)  评论(0编辑  收藏  举报