zoukankan      html  css  js  c++  java
  • 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"),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;
    }
  • 相关阅读:
    到达波密
    福建
    到达拉萨
    樟木半天游
    修改控制寄存器GPBCON
    WINCE实现屏幕旋转的方法
    6410主频
    如何解决触摸屏抖动问题
    视频格式D1
    安家了
  • 原文地址:https://www.cnblogs.com/kernel0815/p/3847700.html
Copyright © 2011-2022 走看看