当前位置: 首页>>代码示例>>C++>>正文


C++ PacketStream::recvfrom方法代码示例

本文整理汇总了C++中PacketStream::recvfrom方法的典型用法代码示例。如果您正苦于以下问题:C++ PacketStream::recvfrom方法的具体用法?C++ PacketStream::recvfrom怎么用?C++ PacketStream::recvfrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PacketStream的用法示例。


在下文中一共展示了PacketStream::recvfrom方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
开发者ID:AnsonX10,项目名称:bitfighter,代码行数:59,代码来源:tnlping.cpp

示例2: checkIncomingPackets

void NetInterface::checkIncomingPackets()
{
   PacketStream stream;
   NetError error;
   Address sourceAddress;

   mCurrentTime = Platform::getRealMilliseconds();

   // read out all the available packets:
   while((error = stream.recvfrom(mSocket, &sourceAddress)) == NoError)
      processPacket(sourceAddress, &stream);
}
开发者ID:HwakyoungLee,项目名称:opentnl,代码行数:12,代码来源:netInterface.cpp


注:本文中的PacketStream::recvfrom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。