#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. [物理学与PDEs]书中一些对数学研究有用的引理

    P 35--38 1.  若 ${\bf B}$ 为横场 ($\Div{\bf B}=0\ra {\bf k}\cdot {\bf B}=0\ra $ 波的振动方向与传播方向平行), 则 $$\bex ...

  2. 简单且线程安全的两个单例模式java程序

    /***具体说明见 http://www.cnblogs.com/coffee/archive/2011/12/05/inside-java-singleton.html*/ package com. ...

  3. c语言知识(2)

    while(n)首先,n在这里被当作了一个条件其次,当n为真时,进入while循环体(A):否则跳出循环继续执行下面部分(B).n为0时条件为假  n不为0条件为真 while(j) { if(j%1 ...

  4. htmlparser日记

    myParser = Parser.createParser(response, "utf-8");NodeFilter tableFilter = new NodeClassFi ...

  5. NLog文章系列——如何配置NLog

    NLog支持以多种不同方式配置,目前同时支持直接编程和使用配置文件两种方法.本文将对目前支持的各种配置方式作详细描述. 日志配置 通过在启动的时候对一些常用目录的扫描,NLog会尝试使用找到的配置信息 ...

  6. 学习MVC框架的步骤

    1.搭建环境 2.了解控制层和视图层的映射 3.控制层和视图层的传值 交互 4.异常处理 5.页面标签 6.文件上传 7.框架源代码

  7. clipse在编写JSP时没有代码提示

    alt /不会出提示按照下面步骤做 1.菜单window- >Preferences- >Java- >Editor- >Content Assist- >Enable ...

  8. ArcGIS上根据经纬度求地球表面两点间距离的实现

    ArcGIS上根据经纬度求地球表面两点间距离的实现 以米为单位..Net2.0,C#实现.        public static double DistanceOfTwoPoints(double ...

  9. java使用jacob将office转pdf

    1.此处代码是把office文档转换成pdf的工具类,在BS架构的产品中,我们可以使用基于JS的pdf插件显示pdf文档,但是前提IE需要按照adobe的pdf软件,对于非IE不用安装.2.可以基于f ...

  10. 安装小企鹅fcitx输入法

    ##编辑~/.xinitrc文件,添加:export GTK_IM_MODULE=fcitx export QT_IM_MODULE=fcitx export XMODIFIERS="@im ...