main.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. #include "TelnetTransport.h"
  11. #include "ConsoleServer.h"
  12. #include "LogCommandParser.h"
  13. #include "PacketConsoleLogger.h"
  14. #include "RakPeerInterface.h"
  15. #include "RakSleep.h"
  16. #include <stdio.h>
  17. #include "Getche.h"
  18. #include "MessageIdentifiers.h"
  19. #include "Kbhit.h"
  20. using namespace RakNet;
  21. void main(void)
  22. {
  23. printf("Shows how to connect telnet to read PacketLogger output from RakPeer.\n");
  24. RakPeerInterface *rakPeer = RakNet::RakPeerInterface::GetInstance();
  25. TelnetTransport tt;
  26. ConsoleServer consoleServer;
  27. LogCommandParser lcp;
  28. PacketConsoleLogger pcl;
  29. pcl.SetLogCommandParser(&lcp);
  30. consoleServer.AddCommandParser(&lcp);
  31. consoleServer.SetTransportProvider(&tt, 23);
  32. rakPeer->AttachPlugin(&pcl);
  33. RakNet::SocketDescriptor sd(0,0);
  34. RakNet::StartupResult sr = rakPeer->Startup(32, &sd, 1);
  35. (void) sr;
  36. RakAssert(sr==RAKNET_STARTED);
  37. printf("Use telnet 127.0.0.1 23 to connect from the command window\n");
  38. printf("Use 'Turn Windows features on and off' with 'Telnet Client' if needed.\n");
  39. printf("Once telnet has connected, type 'Logger subscribe'\n");
  40. printf("Press any key in this window once you have done all this.\n");
  41. RakNet::Packet *packet;
  42. while (!kbhit())
  43. {
  44. consoleServer.Update();
  45. RakSleep(30);
  46. }
  47. RakNet::ConnectionAttemptResult car = rakPeer->Connect("natpunch.jenkinssoftware.com", 61111, 0, 0);
  48. (void) car;
  49. while (1)
  50. {
  51. for (packet=rakPeer->Receive(); packet; rakPeer->DeallocatePacket(packet), packet=rakPeer->Receive())
  52. {
  53. }
  54. consoleServer.Update();
  55. RakSleep(30);
  56. }
  57. }
粤ICP备19079148号