2019-04-22 21:03:00 +03:00
|
|
|
/*******************************************************************************************
|
|
|
|
*
|
|
|
|
* raylib [network] example - Resolve Host
|
2020-02-19 20:16:20 +03:00
|
|
|
*
|
|
|
|
* This example has been created using raylib 3.0 (www.raylib.com)
|
|
|
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2019-2020 Jak Barnes (@syphonx) and Ramon Santamaria (@raysan5)
|
|
|
|
*
|
|
|
|
********************************************************************************************/
|
2019-04-22 21:03:00 +03:00
|
|
|
|
2020-02-19 20:16:20 +03:00
|
|
|
#include "raylib.h"
|
2019-04-22 21:03:00 +03:00
|
|
|
|
2020-02-19 20:16:20 +03:00
|
|
|
#define RNET_IMPLEMENTATION
|
|
|
|
#include "rnet.h"
|
2019-04-22 21:03:00 +03:00
|
|
|
|
2020-02-19 20:16:20 +03:00
|
|
|
int main(void)
|
2019-04-22 21:03:00 +03:00
|
|
|
{
|
2020-02-19 20:16:20 +03:00
|
|
|
// Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
const int screenWidth = 800;
|
|
|
|
const int screenHeight = 450;
|
2019-04-22 21:03:00 +03:00
|
|
|
|
2020-02-19 20:16:20 +03:00
|
|
|
InitWindow(screenWidth, screenHeight, "raylib [network] example - ping pong");
|
|
|
|
|
|
|
|
char buffer[ADDRESS_IPV6_ADDRSTRLEN];
|
|
|
|
uint16_t port = 0;
|
|
|
|
|
2019-08-03 12:07:41 +03:00
|
|
|
SetTraceLogLevel(LOG_DEBUG);
|
2019-04-22 21:03:00 +03:00
|
|
|
|
2020-02-19 20:16:20 +03:00
|
|
|
|
2019-08-03 12:07:41 +03:00
|
|
|
// Networking
|
2020-02-19 20:16:20 +03:00
|
|
|
InitNetworkDevice();
|
2019-08-03 12:07:41 +03:00
|
|
|
|
2019-04-22 21:03:00 +03:00
|
|
|
AddressInformation* addr = AllocAddressList(1);
|
2019-08-03 12:07:41 +03:00
|
|
|
int count = ResolveHost(
|
|
|
|
NULL,
|
|
|
|
"5210",
|
|
|
|
ADDRESS_TYPE_IPV4,
|
2019-04-22 21:03:00 +03:00
|
|
|
0 // Uncomment any of these flags
|
|
|
|
// ADDRESS_INFO_NUMERICHOST // or try them in conjunction to
|
|
|
|
// ADDRESS_INFO_NUMERICSERV // specify custom behaviour from
|
|
|
|
// ADDRESS_INFO_DNS_ONLY // the function getaddrinfo()
|
|
|
|
// ADDRESS_INFO_ALL //
|
|
|
|
// ADDRESS_INFO_FQDN // e.g. ADDRESS_INFO_CANONNAME | ADDRESS_INFO_NUMERICSERV
|
2019-08-03 12:07:41 +03:00
|
|
|
,
|
2019-04-22 21:03:00 +03:00
|
|
|
addr
|
|
|
|
);
|
|
|
|
|
|
|
|
if (count > 0)
|
|
|
|
{
|
|
|
|
GetAddressHostAndPort(addr[0], buffer, &port);
|
2020-02-19 20:16:20 +03:00
|
|
|
TraceLog(LOG_INFO, "Resolved to ip %s::%d", buffer, port);
|
2019-04-22 21:03:00 +03:00
|
|
|
}
|
|
|
|
|
2020-02-19 20:16:20 +03:00
|
|
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
2019-08-03 12:07:41 +03:00
|
|
|
// Main game loop
|
2020-02-19 20:16:20 +03:00
|
|
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
2019-08-03 12:07:41 +03:00
|
|
|
{
|
2020-02-19 20:16:20 +03:00
|
|
|
// Update
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
// TODO: Update your variables here
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
2019-08-03 12:07:41 +03:00
|
|
|
// Draw
|
2020-02-19 20:16:20 +03:00
|
|
|
//----------------------------------------------------------------------------------
|
2019-08-03 12:07:41 +03:00
|
|
|
BeginDrawing();
|
2019-04-22 21:03:00 +03:00
|
|
|
|
2020-02-19 20:16:20 +03:00
|
|
|
ClearBackground(RAYWHITE);
|
|
|
|
|
|
|
|
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
2019-04-22 21:03:00 +03:00
|
|
|
|
2019-08-03 12:07:41 +03:00
|
|
|
EndDrawing();
|
2020-02-19 20:16:20 +03:00
|
|
|
//----------------------------------------------------------------------------------
|
2019-08-03 12:07:41 +03:00
|
|
|
}
|
2019-04-22 21:03:00 +03:00
|
|
|
|
2020-02-19 20:16:20 +03:00
|
|
|
// De-Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
CloseWindow(); // Close window and OpenGL context
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
2019-08-03 12:07:41 +03:00
|
|
|
return 0;
|
2019-04-22 21:03:00 +03:00
|
|
|
}
|