本文整理汇总了C++中raknet::BitStream::PadWithZeroToByteLength方法的典型用法代码示例。如果您正苦于以下问题:C++ BitStream::PadWithZeroToByteLength方法的具体用法?C++ BitStream::PadWithZeroToByteLength怎么用?C++ BitStream::PadWithZeroToByteLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类raknet::BitStream
的用法示例。
在下文中一共展示了BitStream::PadWithZeroToByteLength方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
RakPeerInterface *rakPeer;
char str[256];
char ip[32];
unsigned short remotePort, localPort;
RakNet::Packet *packet;
printf("This project tests sending a burst of messages to a remote system.\n");
printf("Difficulty: Beginner\n\n");
rakPeer = RakNet::RakPeerInterface::GetInstance();
printf("Enter remote IP (enter to not connect): ");
Gets(ip, sizeof(ip));
if (ip[0])
{
printf("Enter remote port: ");
Gets(str, sizeof(str));
if (str[0]==0)
strcpy(str, "60000");
remotePort=atoi(str);
printf("Enter local port: ");
Gets(str, sizeof(str));
if (str[0]==0)
strcpy(str, "0");
localPort=atoi(str);
RakNet::SocketDescriptor socketDescriptor(localPort,0);
rakPeer->Startup(32, &socketDescriptor, 1);
printf("Connecting...\n");
rakPeer->Connect(ip, remotePort, 0, 0);
}
else
{
printf("Enter local port: ");
Gets(str, sizeof(str));
if (str[0]==0)
strcpy(str, "60000");
localPort=atoi(str);
RakNet::SocketDescriptor socketDescriptor(localPort,0);
rakPeer->Startup(32, &socketDescriptor, 1);
}
rakPeer->SetMaximumIncomingConnections(32);
printf("'s' to send. ' ' for statistics. 'q' to quit.\n");
while (1)
{
if (kbhit())
{
char ch=getch();
if (ch=='q')
return 1;
else if (ch==' ')
{
RakNetStatistics *rss;
char message[2048];
rss=rakPeer->GetStatistics(rakPeer->GetSystemAddressFromIndex(0));
StatisticsToString(rss, message, 2);
printf("%s", message);
}
else if (ch=='s')
{
char msgSizeStr[128], msgCountStr[128];
uint32_t msgSize, msgCount,index;
printf("Enter message size in bytes: ");
Gets(msgSizeStr, sizeof(msgSizeStr));
if (msgSizeStr[0]==0)
msgSize=4096;
else
msgSize=atoi(msgSizeStr);
printf("Enter times to repeatedly send message: ");
Gets(msgCountStr, sizeof(msgCountStr));
if (msgCountStr[0]==0)
msgCount=128;
else
msgCount=atoi(msgCountStr);
RakNet::BitStream bitStream;
for (index=0; index < msgCount; index++)
{
bitStream.Reset();
bitStream.Write((MessageID)ID_USER_PACKET_ENUM);
bitStream.Write(msgSize);
bitStream.Write(index);
bitStream.Write(msgCount);
bitStream.PadWithZeroToByteLength(msgSize);
rakPeer->Send(&bitStream, MEDIUM_PRIORITY, RELIABLE_ORDERED, 0, UNASSIGNED_SYSTEM_ADDRESS, true);
}
printf("Sent\n");
}
}
for (packet=rakPeer->Receive(); packet; rakPeer->DeallocatePacket(packet), packet=rakPeer->Receive())
{
switch(packet->data[0])
//.........这里部分代码省略.........