本文整理汇总了C++中PacketStream::read方法的典型用法代码示例。如果您正苦于以下问题:C++ PacketStream::read方法的具体用法?C++ PacketStream::read怎么用?C++ PacketStream::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PacketStream
的用法示例。
在下文中一共展示了PacketStream::read方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, const char **argv)
{
if(argc < 2)
{
printf("Usage: tnlping <remoteAddress> [sourceAddress]\n\n"
"Example 1: Simple usage expecting port 28000\n tnlping 192.168.1.2\n\n"
"Example 2: Advanced usage with specific port\n tnlping 192.168.1.2:28001\n\n");
return 1;
}
U8 randData[sizeof(U32) + sizeof(S64)];
*((U32 *) randData) = Platform::getRealMilliseconds();
*((S64 *) (randData + sizeof(U32))) = Platform::getHighPrecisionTimerValue();
TNL::Random::addEntropy(randData, sizeof(randData));
Address remoteAddress(argv[1]);
Address sourceAddress(argc > 2 ? argv[2] : "IP:Any:0");
Nonce clientNonce;
clientNonce.getRandom();
Socket sourceSocket(sourceAddress);
PacketStream out;
out.write(U8(NetInterface::ConnectChallengeRequest));
clientNonce.write(&out);
out.writeFlag(false);
out.writeFlag(false);
for(U32 tryCount = 0; tryCount < 5; tryCount++)
{
U32 time = Platform::getRealMilliseconds();
out.sendto(sourceSocket, remoteAddress);
for(;;)
{
PacketStream incoming;
Address incomingAddress;
if(incoming.recvfrom(sourceSocket, &incomingAddress) == NoError)
{
U8 packetType;
Nonce theNonce;
incoming.read(&packetType);
theNonce.read(&incoming);
if(packetType == NetInterface::ConnectChallengeResponse && theNonce == clientNonce)
{
printf("TNL Service is UP (pingtime = %d)\n", Platform::getRealMilliseconds() - time);
return 0;
}
}
Platform::sleep(1);
if(Platform::getRealMilliseconds() - time > 1000)
break;
}
}
printf("TNL Service is DOWN\n");
return 1;
}