码迷,mamicode.com
首页 > 其他好文 > 详细

boost: tcp client sample

时间:2014-07-16 17:43:45      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   art   for   

#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;
}

 

boost: tcp client sample,布布扣,bubuko.com

boost: tcp client sample

标签:style   blog   color   os   art   for   

原文地址:http://www.cnblogs.com/kernel0815/p/3847700.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!