飞鸽传书数据包
来源:互联网 发布:matlab 矩阵怎么输入 编辑:程序博客网 时间:2024/04/28 04:07
// XDATA01.cpp: implementation of the XDATA01 class.
//
//////////////////////////////////////////////////////////////////////
// 一款流传非常广的局域网实用软件,可惜俺这几天才开始使用。相比与弱弱的 Windows 文件共享系统,飞鸽传书实用性,速度,快捷,方便程度上都有提高,也就是说这俩就不在一个等级上,哈哈。通讯协议模拟,只用于研究飞鸽传书时用,无其他实际用途。
#include "stdafx.h"
#include "XDATA01.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
XDATA01::XDATA01()
{
m_bData = NULL;
m_nDataLength = 0;
}
XDATA01::~XDATA01()
{
if (m_bData)
{
// printf("free data buffer./n");
free(m_bData);
m_bData = NULL;
m_nDataLength = 0;
}
}
// 把数据保存到飞鸽传书数据结构中,字符串用 strlen 时,必须 +1 来包括 NULL
void XDATA01::SetData(char *bData, int nLength)
{
if (m_bData)
{
// printf("free data buffer./n");
free(m_bData);
m_bData = NULL;
m_nDataLength = 0;
}
m_nDataLength = nLength;
m_bData = (char*)malloc(sizeof(char) * nLength);
memcpy(m_bData, bData, nLength);
}
// 返回数据飞鸽传书的长度
int XDATA01::GetLength()
{
return m_nDataLength;
}
// 返回数据
char * XDATA01::GetData()
{
return m_bData;
}
// 把整个数据打包,飞鸽传书用来发送
char *XDATA01::GetBuffer()
{
char *temp;
int nPtr = 0;
temp = new char[GetBufferLength()];
memcpy(temp, (char*)&m_nDataLength, sizeof(int));
nPtr = sizeof(int);
memcpy(temp+nPtr, m_bData, m_nDataLength);
return temp;
}
// 飞鸽传书数据包的长度
int XDATA01::GetBufferLength()
{
int len;
len = m_nDataLength + sizeof(int);
return len;
}
// imp01.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "XDATA01.h"
void test()
{
XDATA01 xdata;
// printf("sizeof of XDATA01: %d./n", sizeof(XDATA01));
xdata.SetData("Hello.", strlen("Hello.")+1);
// 测试之前的数据是否被释放
xdata.SetData("Hello.", strlen("Hello.")+1);
// printf("data:%s, len:%d/n", xdata.GetData(), xdata.GetLength());
}
int main(int argc, char* argv[])
{
for (int i=0; i<2; i++)
test();
return 0;
}
- 飞鸽传书数据包
- 飞鸽传书
- 飞鸽传书
- 飞鸽传书
- 飞鸽传书
- 数据包
- 数据包
- 飞鸽传书2011下载(飞鸽传书)
- 【飞鸽传书】飞鸽传书2011绿色版
- 飞鸽传书,又见飞鸽传书,
- 大飞鸽传书!小飞鸽传书!
- 什么是飞鸽传书
- 什么是飞鸽传书
- 新版飞鸽传书
- 飞鸽传书2007
- 飞鸽传书2007
- 飞鸽传书简介
- 飞鸽传书提速
- Windows下不注销或重启更换用户身份访问文件服务器
- 目标归来---J2ME
- 飞鸽传书传文件
- 友情链接交换技巧?
- 自旋锁入门
- 飞鸽传书数据包
- Sharpening Your Skills: Managing Teams
- ubuntu下最好用的防火墙shadaarp ,带主动防御
- 参考文献
- LWUIT之时间控件显示中文
- VC.net中使用GDI+的方法
- 研究生课程 软件测试12: Usability Testing
- LWUIT使用带有混淆器导出时的注意事项
- HTML连续英文字符串强制换行