本文整理汇总了C++中ArNetPacket::dataToBuf方法的典型用法代码示例。如果您正苦于以下问题:C++ ArNetPacket::dataToBuf方法的具体用法?C++ ArNetPacket::dataToBuf怎么用?C++ ArNetPacket::dataToBuf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArNetPacket
的用法示例。
在下文中一共展示了ArNetPacket::dataToBuf方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: putFile
void putFile(char *fileName, char *asFileName)
{
ArNetPacket sendPacket;
size_t ui;
size_t len;
FILE *file;
if ((file = ArUtil::fopen(fileName, "r")) == NULL)
{
ArLog::log(ArLog::Normal,
"putFile: can't open file '%s'", fileName);
return;
}
// tell the server we're sending
sendPacket.empty();
sendPacket.uByte2ToBuf(0);
sendPacket.strToBuf(asFileName);
client.requestOnce("putFile", &sendPacket);
printf("Starting send of file %s\n", fileName);
char buf[30000];
size_t ret;
// now send the file
while ((ret = fread(buf, 1, sizeof(buf), file)) == sizeof(buf))
{
sendPacket.empty();
sendPacket.uByte2ToBuf(1);
sendPacket.strToBuf(asFileName);
sendPacket.uByte4ToBuf(ret);
sendPacket.dataToBuf(buf, ret);
client.requestOnce("putFile", &sendPacket);
printf("Sent packet with %d\n", ret);
}
if (ferror(file))
{
ArLog::log(ArLog::Normal, "ArServerFileToClient: Error sending file %s",
fileName);
sendPacket.empty();
sendPacket.uByte2ToBuf(3);
sendPacket.strToBuf(asFileName);
client.requestOnce("putFile", &sendPacket);
return;
}
sendPacket.empty();
sendPacket.uByte2ToBuf(1);
sendPacket.strToBuf(asFileName);
sendPacket.uByte4ToBuf(ret);
sendPacket.dataToBuf(buf, ret);
client.requestOnce("putFile", &sendPacket);
printf("Sent packet with %d\n", ret);
sendPacket.empty();
sendPacket.uByte2ToBuf(2);
sendPacket.strToBuf(asFileName);
client.requestOnce("putFile", &sendPacket);
if (feof(file))
{
ArLog::log(ArLog::Normal, "ArServerFileToClient: Sent file %s", fileName);
}
fclose(file);
}