代码网络收集 修改了一个编译的小问题

客户端

// Client.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include <iostream> #include <boost/asio.hpp> int main()
{
namespace ip = boost::asio::ip;
boost::asio::io_service io_service; // Client binds to any address on port 8888 (the same port on which
// broadcast data is sent from server).
ip::udp::socket socket(io_service,
ip::udp::endpoint(ip::udp::v4(), 8888)); ip::udp::endpoint sender_endpoint; // Receive data.
//boost::array<char, 4> buffer;
char buf[500] = { 0 };
std::size_t bytes_transferred =
socket.receive_from(boost::asio::buffer(buf), sender_endpoint); std::cout << "got " << bytes_transferred << " bytes." << buf <<std::endl;
}

  服务端

// Server.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include <boost/asio.hpp> int main()
{
namespace ip = boost::asio::ip;
boost::asio::io_service io_service; // Server binds to any address and any port.
ip::udp::socket socket(io_service,
ip::udp::endpoint(ip::udp::v4(), 0));
socket.set_option(boost::asio::socket_base::broadcast(true)); // Broadcast will go to port 8888.
ip::udp::endpoint broadcast_endpoint(ip::address_v4::broadcast(), 8888); // Broadcast data.
//boost::array<char, 4> buffer;
char* buf = "测试代码";
socket.send_to(boost::asio::buffer(buf,strlen(buf)+1), broadcast_endpoint);
}

  

最新文章

  1. Daily Scrum Meeting ——EighthDay
  2. XAF点滴:很具体很用实用---处理三个小问题
  3. kaggle数据挖掘竞赛初步--Titanic&lt;随机森林&amp;特征重要性&gt;
  4. 关于asp.net impersonation的一些谣传
  5. 20160817_Redis配置操作
  6. 20个最漂亮的基于WordPress的企业网站
  7. iOS的I/O操作
  8. select实现输入模糊匹配与选择双重功能
  9. 转。管理Gearman
  10. iOS项目开发中的目录结构
  11. 去蓝港在线面试Unity3D的笔试题。难吗?知道答案的在评论里写出来分享
  12. iOS开发那些事儿(四)the dark arts of the Objective-C runtime
  13. 蓝桥杯java高职组
  14. CodeForces 660D Number of Parallelograms
  15. Javascript自动化文档工具JSDuck在Windows下的使用心得
  16. vscode 中 eslint 相关配置
  17. dts中memreserve和reserved-memory的区别 (转)
  18. 【OpenGL】第一个窗口
  19. .Net(c#)加密解密工具类:
  20. 配置Spring框架编写XML的提示

热门文章

  1. Postman的基础使用
  2. 使用 SignalR与SSE(Sever sent event)向客户端推送提示信息
  3. TCP/IP协议和IP
  4. c++builder XE7 C++11 C++0x 新语法
  5. Activity服务类-7 RepositoryService服务类
  6. jquery formValidator 表单验证插件, ajax无法传值到后台问题的解决
  7. hibernate-注解及配置
  8. 在JSP中,使用get提交方式出现乱码时,为什么要使用new String(s.getBytes(&quot;iso-8859-1&quot;),&quot;utf-8&quot;);?
  9. Mysql count+if 函数结合使用
  10. while and for 2