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.

77 lines
2.9 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [network] example - Resolve Host
  4. *
  5. * This example has been created using raylib 3.0 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2019-2020 Jak Barnes (@syphonx) and Ramon Santamaria (@raysan5)
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. #define RNET_IMPLEMENTATION
  13. #include "rnet.h"
  14. int main(void)
  15. {
  16. // Initialization
  17. //--------------------------------------------------------------------------------------
  18. const int screenWidth = 800;
  19. const int screenHeight = 450;
  20. InitWindow(screenWidth, screenHeight, "raylib [network] example - resolve host");
  21. InitNetworkDevice(); // Init network communications
  22. char buffer[ADDRESS_IPV6_ADDRSTRLEN];
  23. unsigned short port = 0;
  24. AddressInformation *address = LoadAddressList(1);
  25. // Address info flags
  26. // ADDRESS_INFO_NUMERICHOST // or try them in conjunction to
  27. // ADDRESS_INFO_NUMERICSERV // specify custom behaviour from
  28. // ADDRESS_INFO_DNS_ONLY // the function getaddrinfo()
  29. // ADDRESS_INFO_ALL //
  30. // ADDRESS_INFO_FQDN // e.g. ADDRESS_INFO_CANONNAME | ADDRESS_INFO_NUMERICSERV
  31. int count = ResolveHost(NULL, "5210", ADDRESS_TYPE_IPV4, 0, address);
  32. if (count > 0)
  33. {
  34. GetAddressHostAndPort(address[0], buffer, &port);
  35. TraceLog(LOG_INFO, "Resolved to ip %s::%d", buffer, port);
  36. }
  37. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  38. //--------------------------------------------------------------------------------------
  39. // Main game loop
  40. while (!WindowShouldClose()) // Detect window close button or ESC key
  41. {
  42. // Update
  43. //----------------------------------------------------------------------------------
  44. // TODO: Update your variables here
  45. //----------------------------------------------------------------------------------
  46. // Draw
  47. //----------------------------------------------------------------------------------
  48. BeginDrawing();
  49. ClearBackground(RAYWHITE);
  50. // TODO: Draw relevant connection info
  51. EndDrawing();
  52. //----------------------------------------------------------------------------------
  53. }
  54. // De-Initialization
  55. //--------------------------------------------------------------------------------------
  56. CloseNetworkDevice(); // Close network communication
  57. CloseWindow(); // Close window and OpenGL context
  58. //--------------------------------------------------------------------------------------
  59. return 0;
  60. }