#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 ;
}

最新文章

  1. Celery 框架学习笔记
  2. 【JavaScript回顾】继承
  3. js统计字符串中各种字符情况
  4. javascript正则表达式替换字符串
  5. spring3.0事务的配置
  6. Learning Lua Programming (4) Cocos2d-x中Lua编程(一)
  7. Java就业前景怎么样?学了后好找工作吗?
  8. GIT入门笔记(6)- 向版本库添加文本文件
  9. CMake设置FOLDER失败及解决
  10. 关联管理器(RelatedManager)
  11. python面向对象的知识梳理
  12. irc 关键操作
  13. nginx配置静态webserver
  14. Xshell 无法连接虚拟机中的ubuntu的问题
  15. 安装配置Spark集群
  16. wrk 压测中请求无法响应问题解决过程
  17. centos中文字符集,中文日志
  18. JavaScript 删除 ASP.NET 设置的多值 Cookie 的方法
  19. C#或Python中正则表达式元字符含意
  20. 战争迷雾Fog Of War

热门文章

  1. Sublime 编译出来的是 dos格式,不是unix格式
  2. 系统yum源更新及某些软件官方源安装
  3. 值不能为 null 或为空。参数名: linkText
  4. UBUNTU查看软件版本
  5. clone代码
  6. 【cl】sikuli启动不了
  7. C#开发COM组件供其他开发环境或工具调用介绍(转)
  8. sql server 与oracle数据互导的一种思路--sql server链接服务器
  9. 立体匹配:关于理解middlebury提供的立体匹配代码后的精减
  10. LeetCode Lowest Common Ancestor of a Binary Serach Tree