raylib/examples/network/network_resolve_host.c

85 lines
3.0 KiB
C
Raw Normal View History

/*******************************************************************************************
*
* 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)
*
********************************************************************************************/
2020-02-19 20:16:20 +03:00
#include "raylib.h"
2020-02-19 20:16:20 +03:00
#define RNET_IMPLEMENTATION
#include "rnet.h"
2020-02-19 20:16:20 +03:00
int main(void)
{
2020-02-19 20:16:20 +03:00
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
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;
SetTraceLogLevel(LOG_DEBUG);
2020-02-19 20:16:20 +03:00
// Networking
2020-02-19 20:16:20 +03:00
InitNetworkDevice();
AddressInformation* addr = AllocAddressList(1);
int count = ResolveHost(
NULL,
"5210",
ADDRESS_TYPE_IPV4,
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
,
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);
}
2020-02-19 20:16:20 +03:00
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
2020-02-19 20:16:20 +03:00
while (!WindowShouldClose()) // Detect window close button or ESC key
{
2020-02-19 20:16:20 +03:00
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
//----------------------------------------------------------------------------------
// Draw
2020-02-19 20:16:20 +03:00
//----------------------------------------------------------------------------------
BeginDrawing();
2020-02-19 20:16:20 +03:00
ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
EndDrawing();
2020-02-19 20:16:20 +03:00
//----------------------------------------------------------------------------------
}
2020-02-19 20:16:20 +03:00
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}