本文整理汇总了C++中NetConnection::SendPackets方法的典型用法代码示例。如果您正苦于以下问题:C++ NetConnection::SendPackets方法的具体用法?C++ NetConnection::SendPackets怎么用?C++ NetConnection::SendPackets使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetConnection
的用法示例。
在下文中一共展示了NetConnection::SendPackets方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _tmain
//.........这里部分代码省略.........
printf("Unreliable message sending passed!\n\n");
//test unreliable splitting
printf("Testing unreliable message splitting...\n");
num = 50;
while(num-- > 0)
{
int data[800];
for (int i = 0; i < 800; i++)
{
data[i] = rand();
}
connection.Send((char*)data, sizeof(data));
//ok, now check
Peer* sender; int size;
while (true)
{
char* buffer = server.Receive(sender, size);
if (buffer)
{
if (size == sizeof(data))
{
for (int i = 0; i < 800; i++)
{
assert(((int*)buffer)[i] == data[i]);
}
}
else
{
printf("Bad message size!!!\n");
}
delete[] buffer;
break;
}
}
}
printf("Unreliable message splitting sending passed!\n\n");
//test packet coalesing
printf("Testing unreliable message coalescing...\n");
num = 50;
while(num-- > 0)
{
int data[121];
for (int i = 0; i < 121; i++)
{
data[i] = rand();
}
connection.Send((char*)data, sizeof(data));
connection.Send((char*)data, sizeof(data));
connection.Send((char*)data, sizeof(data));
connection.SendPackets();//force send
//ok, now check
Peer* sender; int size;
for (int i = 0; i < 3; i++)
{
while (true)
{
char* buffer = server.Receive(sender, size);
if (buffer)
{
if (size == sizeof(data))
{
for (int i = 0; i < 121; i++)
{
assert(((int*)buffer)[i] == data[i]);
}
}
else
{
printf("Bad message size!!!\n");
}
delete[] buffer;
break;
}
}
}
}
printf("Unreliable message coalescing passed!\n\n");
printf("Testing Disconnection...\n");
connection.Disconnect();
while (true)
{
Peer* sender; int size;
server.Receive(sender, size);
if (server.peers.size() == 0)
break;
}
printf("Disconnection successful!\n");
//while (true)
NetSleep(10000);
return 0;
}