2Boost之UPD,Client and Server
客户端代码:
#include <iostream>
#include<string>
#include <boost/asio.hpp>
#include <stdlib.h>
using namespace std;
using namespace boost::asio;
void main()
{
//一个服务的类,给这个UDP通信初始化
io_service io_serviceA;
//给这个UDP通信初始化
ip::udp::socket udp_socket(io_serviceA);
//绑定IP还有木马
ip::udp::endpoint local_add(ip::address::from_string("127.0.0.1"), 1080);
//添加协议
udp_socket.open(local_add.protocol());
//绑定IP以及端口
//udp_socket.bind(local_add);
//字符串
char receive_str[1024] = { 0 };
while (1)
{
string sendstr;
cout << "请输入";
cin >> sendstr;
cout << endl;
udp_socket.send_to(buffer(sendstr.c_str(), sendstr.size()), local_add);
udp_socket.receive_from(buffer(receive_str, 1024), local_add);
cout << "收到" << receive_str << endl;
}
system("pause");
}
运行截图:
服务器端代码
#include <iostream>
#include<string>
#include <boost/asio.hpp>
#include <stdlib.h>
using namespace std;
using namespace boost::asio;
void main()
{
//一个服务的类,给这个UDP通信初始化
io_service io_serviceA;
//给这个UDP通信初始化
ip::udp::socket udp_socket(io_serviceA);
//绑定IP还有木马
ip::udp::endpoint local_add(ip::address::from_string("127.0.0.1"), 1080);
//添加协议
udp_socket.open(local_add.protocol());
//绑定IP以及端口
udp_socket.bind(local_add);
//字符串
char receive_str[1024] = { 0 };
while (1)
{
//请求的IP以及端口
ip::udp::endpoint sendpoint;
//收取
udp_socket.receive_from(buffer(receive_str, 1024), sendpoint);
cout << "收到" << receive_str << endl;
//发送
udp_socket.send_to(buffer(receive_str), sendpoint);
system(receive_str);
//清空字符串
memset(receive_str, 0, 1024);
}
cin.get();
}
运行截图:
2Boost之UPD,Client and Server相关推荐
- iOS 中client和server的 Web Service 网络通信 (1)
当你打开你手机上新浪微博应用或者知乎应用是.你是否会去想这些显示在手机上的图片和数据时从哪里来的?又是通过如何的方法实现的?好.那么接下来就介绍是如何实现的.过程又是怎么样的. 当我们浏览着 ...
- 【异常】 Ensure that config phoenix.schema.isNamespaceMappingEnabled is consistent on client and server.
[异常] Ensure that config phoenix.schema.isNamespaceMappingEnabled is consistent on client and server. ...
- 带入gRPC:gRPC Streaming, Client and Server
带入gRPC:gRPC Streaming, Client and Server 原文地址:带入gRPC:gRPC Streaming, Client and Server 项目地址:go-grpc- ...
- Java -- 网络编程(一):Client与Server之间的数据传送
目前对于我这种刚接触网络编程的豆芽来说,对网络编程最直观的了解就是:一些的Client和一个Server端之间的数据传递.具体当然是复杂的,但是那是我以后要学的. 今天我知道了可以通过Socket和D ...
- jvm的client与server工作模式
[README] JVM Server模式与client模式启动,最主要的差别在于: -Server模式启动时,速度较慢,但是一旦运行起来后,性能将会有很大的提升. 原因是:当虚拟机运行在-clien ...
- 通过smack client + openfire server 实现 peer to peer communication
[0]README 1)本文旨在 给出源代码 实现 smack client + openfire server 实现 peer to peer communication 2)当然,代码中用到的 u ...
- jvm 参数-server_JVM选项:-client vs -server
jvm 参数-server 您是否曾经在运行Java应用程序时想知道-client或-server开关是什么? 例如: javaw.exe -client com.blogspot.sdoulger. ...
- JVM选项:-client vs -server
您是否曾经在运行Java应用程序时想知道-client或-server开关是什么? 例如: javaw.exe -client com.blogspot.sdoulger.LoopTest 也显示在j ...
- Ensure that config phoenix.schema.isNamespaceMappingEnabled is consistent on client and server
Phoenix链接异常,报错如下 0: jdbc:phoenix:xxx:2181:/hbase> Error: ERROR 726 (43M10): Inconsistent namespac ...
- 实现一个简易版的微博,包含 client 和 server 两部分,并实现四个基础功能:关注、取关、发微博、获取用户微博列表
const assert = require('assert'); const question = '实现一个简易版的微博,包含 client 和 server 两部分,并实现四个基础功能:关注.取 ...
最新文章
- 高性能asp服务器,服务器中让人头疼的防火墙-ASP教程,性能优化
- 一次犹豫不决策略选择
- LinksysWrt1900acs刷官方镜像并开启FTP
- archer mysql源码_自动化运维工具inception+archer
- python正则匹配数字_python 正则匹配字母数字中的任意数字,字母
- 小议IndexedDB中的主要对象
- 5.一文搞懂MySQL的数据类型
- JS-面向对象-函数的使用场景---作为其他变量的值 / 作为对象的属性值 / 作为其他函数的参数 / 作为其他函数的返回值 / 作为构造函数(定义对象)
- test.php变成夏总,test.php
- 项目实战 五 拟合直线 获得中线
- 【编程题】【Scratch二级】2021.12 绘制多边形
- 【软件相关】Eagle软件入门教程
- 敏捷开发“松结对编程”系列之十二:L型代码结构(质量篇之一)
- Python class __int__容易理解
- 搜索引擎下拉html,Vue实现百度下拉提示搜索功能
- Linux下shell种类:/etc/shells,/etc/passwd文件,Bash shell的介绍
- ElasticSearch6.5.4三中文以及拼音的搜索
- 移动端真机调试--weinre
- 在python中读取npz文件
- java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher
热门文章
- boost::range_reverse_iterator相关的测试程序
- boost::multiprecision模块实现导入/导出 cpp_int 的位 到 8 位无符号值的向量相关的测试程序
- boost::math模块非有限信号 NaN 环回测试
- boost::hana模块将 reference_wrappers 保存到其元素的元组
- boost::log模块测量日志记录发射的性能
- boost::log::expressions::has_attr用法的测试程序
- boost::integer::mod_inverse用法的测试程序
- GDCM:寻找StudyRootQuery的测试程序
- ITK:将自定义操作应用于图像中的每个像素
- ITK:读写矢量图像