#include <iostream>
#include <boost/asio.hpp> using namespace std;
using namespace boost::asio; int main()
{
try
{
cout << "server start." << endl;
io_service ios; ip::tcp::acceptor acc(ios,
ip::tcp::endpoint(ip::tcp::v4(),)); cout << acc.local_endpoint().address() << endl; while (true)
{
ip::tcp::socket sock(ios);
acc.accept(sock); cout << "client:" ;
cout << sock.remote_endpoint().address() << endl; sock.write_some(buffer("hello asio"));
}
}
catch (std::exception& e)
{
cout << e.what() << endl;
} return ;
}

tcp client:

 #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"),); sock.connect(ep); vector<char> str(,);
sock.read_some(buffer(str));
cout << "receive from " << sock.remote_endpoint().address();
cout << &str[] << 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());
at.async_wait(print); cout << "it show before at exired" <<endl;
ios.run();
return ;
}

boost::asio 使用实例的更多相关文章

  1. boost ASIO实例

    client端代码 #include <iostream> #include <boost/asio.hpp> #include <boost/bind.hpp> ...

  2. boost asio异步读写网络聊天程序client 实例具体解释

    boost官方文档中聊天程序实例解说 数据包格式chat_message.hpp <pre name="code" class="cpp">< ...

  3. boost asio异步读写网络聊天程序客户端 实例详解

    boost官方文档中聊天程序实例讲解 数据包格式chat_message.hpp <pre name="code" class="cpp">< ...

  4. boost asio tcp server 拆分

    从官方给出的示例中对于 boost::asio::ip::tcp::acceptor 类的使用,是直接使用构造函数进行构造对象,这一种方法用来学习是一个不错的方式. 但是要用它来做项目却是不能够满足我 ...

  5. boost::asio译文

        Christopher Kohlhoff Copyright © 2003-2012 Christopher M. Kohlhoff 以Boost1.0的软件授权进行发布(见附带的LICENS ...

  6. Boost.Asio c++ 网络编程翻译(14)

    保持活动 假如,你须要做以下的操作: io_service service; ip::tcp::socket sock(service); char buff[512]; ... read(sock, ...

  7. boost asio io_service学习笔记

    构造函数 构造函数的主要动作就是调用CreateIoCompletionPort创建了一个初始iocp. Dispatch和post的区别 Post一定是PostQueuedCompletionSta ...

  8. Boost.Asio技术文档

    Christopher Kohlhoff Copyright © 2003-2012 Christopher M. Kohlhoff 以Boost1.0的软件授权进行发布(见附带的LICENSE_1_ ...

  9. Boost.Asio 网络编程([译]Boost.Asio基本原理)

    转自:https://m.w3cschool.cn/nlzbw/nlzbw-3vs825ya.html Boost.Asio基本原理 这一章涵盖了使用Boost.Asio时必须知道的一些事情.我们也将 ...

随机推荐

  1. 把vector中的string对象导入到字符指针数组中

    #include <iostream>#include <string>#include <vector>//#include <cctype>#inc ...

  2. python (7)读取整个目录的所有文件夹并存入

    一,提取出来一个文件夹中的所有文件名并存入到txt文件中 import os import sys reload(sys) sys.setdefaultencoding('utf-8') path = ...

  3. 关于Switch结构利用

    三大流程结构,循环.分支.if ,循环与条件选择结构用的比较多,而swicth用的比较少,swicth可以用if代替,只不过麻烦,最终都能实现输入和输出的条件对应     Swicth利用       ...

  4. html标签搜索引擎友好度总结

    H系列标签:        H标签当中数H1的权重最高,H1相当于我们一篇作文的标题,H2.H3等标签是属于页面的相关性主题标签,h标签的权重也是相对递减的,如果你没有出现h1,那么h2的权重也就相当 ...

  5. web性能 部分

    雅虎34条提高性能的经验 http://www.cnblogs.com/li0803/archive/2009/09/20/1570581.html 减少http请求 1.尽量合并多个css.js文件 ...

  6. ruby-rails 环境搭建

    https://ruby-china.org/wiki/install_ruby_guide

  7. python 读取文本

    将文本转换到NumPy 数组中,做机器学习或其他任何任务,文本处理的技能必不可少.python 实现实现了很精简强大的文本处理功能: 假设 文件 traindata.csv 中有数据 1000行,3列 ...

  8. SQL SERVER 中的 object_id()函数

    在SQLServer数据库中,如果查询数据库中是否存在指定名称的索引或者外键约束等,经常会用到object_id('name','type')方法,做笔记如下: ? 语法:object_id('obj ...

  9. [ActionScript 3.0] AS3 用于拖动对象时跟随鼠标的缓动效果

    package com.fylibs.components.effects { import flash.display.DisplayObject; import flash.events.Even ...

  10. Codeforces 622F 「数学数论」「数学规律」

    题意: 给定n和k,求 1 ≤ n ≤ 109, 0 ≤ k ≤ 106 思路: 题目中给的提示是对于给定的k我们可以求出一个最高次为k+1的关于n的通项公式. 根据拉格郎日插值法,我们可以通过k+2 ...