You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.2 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [network] example - Resolve Host
  4. *
  5. * Welcome to raylib!
  6. *
  7. * To test examples, just press F6 and execute raylib_compile_execute script
  8. * Note that compiled executable is placed in the same folder as .c file
  9. *
  10. * You can find all basic examples on C:\raylib\raylib\examples folder or
  11. * raylib official webpage: www.raylib.com
  12. *
  13. * Enjoy using raylib. :)
  14. *
  15. * This example has been created using raylib 2.0 (www.raylib.com)
  16. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h
  17. *for details)
  18. *
  19. * Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
  20. *
  21. ********************************************************************************************/
  22. #include "raylib.h"
  23. #include "rnet.h"
  24. char buffer[ADDRESS_IPV6_ADDRSTRLEN];
  25. uint16_t port = 0;
  26. int main()
  27. {
  28. // Setup
  29. int screenWidth = 800;
  30. int screenHeight = 450;
  31. InitWindow(
  32. screenWidth, screenHeight, "raylib [network] example - ping pong");
  33. SetTargetFPS(60);
  34. SetTraceLogLevel(LOG_DEBUG);
  35. // Networking
  36. InitNetwork();
  37. AddressInformation* addr = AllocAddressList(1);
  38. int count = ResolveHost(
  39. NULL,
  40. "5210",
  41. ADDRESS_TYPE_IPV4,
  42. 0 // Uncomment any of these flags
  43. // ADDRESS_INFO_NUMERICHOST // or try them in conjunction to
  44. // ADDRESS_INFO_NUMERICSERV // specify custom behaviour from
  45. // ADDRESS_INFO_DNS_ONLY // the function getaddrinfo()
  46. // ADDRESS_INFO_ALL //
  47. // ADDRESS_INFO_FQDN // e.g. ADDRESS_INFO_CANONNAME | ADDRESS_INFO_NUMERICSERV
  48. ,
  49. addr
  50. );
  51. if (count > 0)
  52. {
  53. GetAddressHostAndPort(addr[0], buffer, &port);
  54. TraceLog(LOG_INFO, "Resolved to ip %s::%d\n", buffer, port);
  55. }
  56. // Main game loop
  57. while (!WindowShouldClose())
  58. {
  59. // Draw
  60. BeginDrawing();
  61. // Clear
  62. ClearBackground(RAYWHITE);
  63. // End draw
  64. EndDrawing();
  65. }
  66. // Cleanup
  67. CloseWindow();
  68. return 0;
  69. }