Service:

#include<boost/asio.hpp>
#include<boost/thread.hpp>
#include<iostream>
#include<string> using namespace std;
using namespace boost::asio; int main()
{
io_service ios;
ip::tcp::acceptor acceptor(ios,ip::tcp::endpoint(ip::tcp::v4(),)); while()
{
ip::tcp::socket socket(ios);
acceptor.accept(socket); cout<<socket.remote_endpoint().address()<<endl;
boost::system::error_code ec; string message; cout<<"Please input a string:"<<endl;
cin>>message; socket.write_some(buffer(message),ec); if(ec)
{
cout<<boost::system::system_error(ec).what()<<endl;
break;
}
} return ;
}

Client:

#include<iostream>
#include<boost/asio.hpp> using namespace std;
using namespace boost::asio; int main(int argc,char *argv[])
{
io_service ios;
ip::tcp::socket socket(ios);
ip::tcp::endpoint endpoint(ip::address_v4::from_string("127.0.0.1"),); boost::system::error_code ec;
socket.connect(endpoint,ec); if(ec)
{
cout<<boost::system::system_error(ec).what()<<endl;
return -;
} char buf[]; size_t len=socket.read_some(buffer(buf),ec);
cout.write(buf,len);
cout<<"\n"; getchar();
return ;
}

boost asio sync的更多相关文章

  1. c++ boost asio库初学习

    前些日子研究了一个c++的一个socket库,留下范例代码给以后自己参考. 同步server: // asio_server.cpp : コンソール アプリケーションのエントリ ポイントを定義します. ...

  2. 如何在多线程leader-follower模式下正确的使用boost::asio。

    #include <assert.h> #include <signal.h> #include <unistd.h> #include <iostream& ...

  3. BOOST.Asio——Tutorial

    =================================版权声明================================= 版权声明:原创文章 谢绝转载  啥说的,鄙视那些无视版权随 ...

  4. BOOST.Asio——Overview

    =================================版权声明================================= 版权声明:原创文章 谢绝转载  啥说的,鄙视那些无视版权随 ...

  5. 网络库crash以及boost asio strand dispath分析

    最近在做服务器的稳定性的相关测试,服务器的网络底层使用的是boost asio,然后自己做的二次封装以更好的满足需求. 服务器昨天晚上发现crash了一次,之前测试了将近半个多月,有一次是莫名的退出了 ...

  6. boost asio tcp server 拆分

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

  7. boost::asio 使用实例

    #include <iostream> #include <boost/asio.hpp> using namespace std; using namespace boost ...

  8. boost.asio源码剖析(四) ---- asio中的泛型概念(concepts)

    * Protocol(通信协议) Protocol,是asio在网络编程方面最重要的一个concept.在第一章中的levelX类图中可以看到,所有提供网络相关功能的服务和I/O对象都需要Protoc ...

  9. boost.asio源码剖析(五) ---- 泛型与面向对象的完美结合

    有人说C++是带类的C:有人说C++是面向对象编程语言:有人说C++是面向过程与面向对象结合的语言.类似的评论网上有很多,虽然正确,却片面,是断章取义之言. C++是实践的产物,C++并没有为了成为某 ...

随机推荐

  1. 本地代码如何通过TortoiserGit提交到GitHub

    昨天博文给大家讲解了一下如何本地安装TortoiseGit http://www.cnblogs.com/xinlj/p/5978730.html,今天为大家讲一下如何通过TortoiseGit将本地 ...

  2. ng-selected ng-change

    <!DOCTYPE HTML><html ng-app="myApp"><head><meta http-equiv="Cont ...

  3. Excel筛选之后如何下拉递增

    1.痛点 Excel表格,通过筛选了之后,再想统计行数,通过单纯的拖动或者填充排序啥的,都无法做到排序或行数递增: 2.解决方案 发现了个excel的公式可以完美解决该问题,赞个,找的好辛苦. 3.大 ...

  4. find命令的拾遗

    find -maxdepth 1 -regextype posix-extended -type f -regex "\./${name}[-\.].*\.(gz|bz2|tgz|zip|t ...

  5. css表示屏幕宽度和高度

    expression(document.body.offsetWidth + "px"); expression(document.body.offsetHeight + &quo ...

  6. H5点击事件兼容各种APP浏览器

    https://github.com/Clouda-team/touchjs/blob/master/touch.min.js <script src="js/jquery.min.j ...

  7. iOS,多媒体,地图相关

    1.本地音频播放 2.本地视频播放 3.使用UIImagePickerController摄像头拍照,录像,照片库浏览 4.使用AVFunction,AVCaptureVideoDataOutput实 ...

  8. ZOJ 2412 Farm Irrigation

    Farm Irrigation Time Limit: 2 Seconds      Memory Limit: 65536 KB Benny has a spacious farm land to ...

  9. 使用IIS发布WCF服务

    上一篇是Windows服务为宿主的WCF服务,现在用IIS为宿主发布WCF服务. 第一步:肯定是新建一个WCF服务啦[是WCF服务应用程序],然后在解决方案上再次添加一个新项目[我们选择WCF服务库, ...

  10. paper 118:计算机视觉、模式识别、机器学习常用牛人主页链接

    牛人主页(主页有很多论文代码) Serge Belongie at UC San Diego Antonio Torralba at MIT Alexei Ffros at CMU Ce Liu at ...