首页 > 其他 > 详细

boost: tcp client sample

时间:2014-07-16 17:43:17      阅读:396      评论:0      收藏:0      [点我收藏+]
#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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!