boost asio sync
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的更多相关文章
- c++ boost asio库初学习
前些日子研究了一个c++的一个socket库,留下范例代码给以后自己参考. 同步server: // asio_server.cpp : コンソール アプリケーションのエントリ ポイントを定義します. ...
- 如何在多线程leader-follower模式下正确的使用boost::asio。
#include <assert.h> #include <signal.h> #include <unistd.h> #include <iostream& ...
- BOOST.Asio——Tutorial
=================================版权声明================================= 版权声明:原创文章 谢绝转载 啥说的,鄙视那些无视版权随 ...
- BOOST.Asio——Overview
=================================版权声明================================= 版权声明:原创文章 谢绝转载 啥说的,鄙视那些无视版权随 ...
- 网络库crash以及boost asio strand dispath分析
最近在做服务器的稳定性的相关测试,服务器的网络底层使用的是boost asio,然后自己做的二次封装以更好的满足需求. 服务器昨天晚上发现crash了一次,之前测试了将近半个多月,有一次是莫名的退出了 ...
- boost asio tcp server 拆分
从官方给出的示例中对于 boost::asio::ip::tcp::acceptor 类的使用,是直接使用构造函数进行构造对象,这一种方法用来学习是一个不错的方式. 但是要用它来做项目却是不能够满足我 ...
- boost::asio 使用实例
#include <iostream> #include <boost/asio.hpp> using namespace std; using namespace boost ...
- boost.asio源码剖析(四) ---- asio中的泛型概念(concepts)
* Protocol(通信协议) Protocol,是asio在网络编程方面最重要的一个concept.在第一章中的levelX类图中可以看到,所有提供网络相关功能的服务和I/O对象都需要Protoc ...
- boost.asio源码剖析(五) ---- 泛型与面向对象的完美结合
有人说C++是带类的C:有人说C++是面向对象编程语言:有人说C++是面向过程与面向对象结合的语言.类似的评论网上有很多,虽然正确,却片面,是断章取义之言. C++是实践的产物,C++并没有为了成为某 ...
随机推荐
- Android NDK常见配置问题的解决方案
添加NDK包时出现"Not a valid NDK directory" 在解压的android-ndk-rxxx文件夹中新建一个txt文件,将名字包括后缀更改为ndk-build ...
- 源码阅读 etherum-block.py
def calc_difficulty(parent, timestamp): config = parent.config offset = parent.difficulty // config[ ...
- swiper.animate~之~可以执行两种动画的升级版的Swiper Animate
1.下载插件swiper.animate-twice.min.js,加载进页面. <!DOCTYPE html> <html> <head> ... < ...
- JMeter学习-032-JMeter常见四种变量简介
在JMeter自动化测试脚本编写过程中,经常需要对测试脚本进行一些参数设置.例如,设置测试计划的全局变量(方便切换不同的测试环境).样本线程(HTTP请求等)的参数传递等. 通常,JMeter中常用的 ...
- Git的.gitignore文件配置
.gitignore是Git工具的配置文件,用于屏蔽某些文件上传到线上. 创建.gitignore 在window系统中,不允许新建文件名以"."开头的文件,所以通过git bas ...
- nodejs的request创建的get和post请求,带参数
1.导入request : var request = require('request'); 2.get请求 request({ timeout:5000, // 设置超时 method:'GET' ...
- lua unit test introduction
Unit Test Unit testing is about testing your code during development, not in production. Typically y ...
- nyist 78 圈水池
http://acm.nyist.net/JudgeOnline/problem.php?pid=78 圈水池 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 有一个 ...
- 亿级Web系统搭建——单机到分布式集群
当一个Web系统从日访问量10万逐步增长到1000万,甚至超过1亿的过程中,Web系统承受的压力会越来越大,在这个过程中,我们会遇到很多的问题.为了解决这些性能压力带来问题,我们需要在Web系统架构层 ...
- 浅谈大型web系统架构
动态应用,是相对于网站静态内容而言,是指以c/c++.php.Java.perl..net等服务器端语言开发的网络应用软件,比如论坛.网络相册.交友.BLOG等常见应用.动态应用系统通常与数据库系统. ...