#include <thread>
#include <string>
#include "Connector.h"
using namespace std;
#pragma warning(disable:4996)
int main()
{
io_service ios;
boost::asio::io_service::work work(ios);
std::thread thd([&ios]{ios.run(); });
Connector conn(ios, "127.0.0.1", 9900);
conn.Start();
string str;
if (!conn.IsConnected())
{
cin >> str;
return -1;
}
const int len = 512;
char line[len] = "";
while (cin >> str)
{
memset(line, '\0', len);
char header[HEAD_LEN] = {};
int totalLen = str.length() + 1 + HEAD_LEN;
std::sprintf(header, "%d", str.length() + 1);
memcpy(line, header, HEAD_LEN);
memcpy(line + HEAD_LEN, str.c_str(), str.length() + 1);
conn.Send(line, totalLen);
}
return 0;
}
C++11编写的socket通信程序
4星 · 超过85%的资源 需积分: 50 13 浏览量
2016-07-03
17:21:41
上传
评论 3
收藏 15.4MB RAR 举报
千秋万代永长存
- 粉丝: 1
- 资源: 7
最新资源
- 杨辉三角(Pascal's Triangle)是一个在数学中非常著名的数列,它以一种特定的模式排列数字,内容以5种代码实例实现
- yolov5数据集:CT图像肾脏、结石检测(2类别,包含训练集、验证集)
- 电力102规约请求报文实录
- RTL8723 linux+安卓驱动 2020版本
- ISO 26262 道路车辆-功能安全-系统级产品开发
- 数据挖掘期末题 选择填空简答
- EKF在CTRV模型上的建模推导
- 用于:https://laoshifu.blog.csdn.net/article/details/138191428 多层创建
- 电力102规约(电能累计量的传输规约)培训
- 「常用」E9外部流程接口
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈