首页 > 代码库 > boost: tcp client sample
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;}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。