diff options
| author | Ray <[email protected]> | 2020-02-19 18:16:20 +0100 |
|---|---|---|
| committer | Ray <[email protected]> | 2020-02-19 18:16:20 +0100 |
| commit | 19390eaf097f2f78b7af188ece92f73388381cb6 (patch) | |
| tree | b406a24b9c40951d7174d71422836e1b0b90059a /examples/network/network_udp_server.c | |
| parent | faff51214079955eb86dc972e1746ad728e6d5e3 (diff) | |
| download | raylib-19390eaf097f2f78b7af188ece92f73388381cb6.tar.gz raylib-19390eaf097f2f78b7af188ece92f73388381cb6.zip | |
[rnet] Examples review -WIP-
Diffstat (limited to 'examples/network/network_udp_server.c')
| -rw-r--r-- | examples/network/network_udp_server.c | 92 |
1 files changed, 49 insertions, 43 deletions
diff --git a/examples/network/network_udp_server.c b/examples/network/network_udp_server.c index 5ab45bb5..1fb8d130 100644 --- a/examples/network/network_udp_server.c +++ b/examples/network/network_udp_server.c @@ -1,28 +1,20 @@ /*******************************************************************************************
*
* raylib [network] example - UDP Server
- *
- * Welcome to raylib!
- *
- * To test examples, just press F6 and execute raylib_compile_execute script
- * Note that compiled executable is placed in the same folder as .c file
- *
- * You can find all basic examples on C:\raylib\raylib\examples folder or
- * raylib official webpage: www.raylib.com
- *
- * Enjoy using raylib. :)
- *
- * This example has been created using raylib 2.0 (www.raylib.com)
- * raylib is licensed under an unmodified zlib/libpng license (View raylib.h
- *for details)
- *
- * Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
- *
- ********************************************************************************************/
+*
+* 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)
+*
+********************************************************************************************/
#include "raylib.h"
+
+#define RNET_IMPLEMENTATION
#include "rnet.h"
+
#include <assert.h>
#include <stdio.h>
#include <string.h>
@@ -41,7 +33,7 @@ char recvBuffer[512]; // Once connected to the network, check the sockets for pending information
// and when information is ready, send either a Ping or a Pong.
-void NetworkUpdate()
+void UpdateNetwork()
{
// CheckSockets
//
@@ -82,18 +74,16 @@ void NetworkUpdate() }
}
-int main()
+int main(void)
{
- // Setup
- int screenWidth = 800;
- int screenHeight = 450;
- InitWindow(
- screenWidth, screenHeight, "raylib [network] example - udp server");
- SetTargetFPS(60);
- SetTraceLogLevel(LOG_DEBUG);
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ const int screenWidth = 800;
+ const int screenHeight = 450;
- // Networking
- InitNetwork();
+ InitWindow(screenWidth, screenHeight, "raylib [network] example - udp server");
+
+ InitNetworkDevice();
// Create the server
//
@@ -104,31 +94,47 @@ int main() // bind
// listen
server_res = AllocSocketResult();
- if (!SocketCreate(&server_cfg, server_res)) {
- TraceLog(LOG_WARNING, "Failed to open server: status %d, errno %d",
- server_res->status, server_res->socket->status);
- } else {
- if (!SocketBind(&server_cfg, server_res)) {
- TraceLog(LOG_WARNING, "Failed to bind server: status %d, errno %d",
- server_res->status, server_res->socket->status);
- }
+ if (!SocketCreate(&server_cfg, server_res))
+ {
+ TraceLog(LOG_WARNING, "Failed to open server: status %d, errno %d", server_res->status, server_res->socket->status);
+ } else
+ {
+ if (!SocketBind(&server_cfg, server_res)) TraceLog(LOG_WARNING, "Failed to bind server: status %d, errno %d", server_res->status, server_res->socket->status);
}
// Create & Add sockets to the socket set
socket_set = AllocSocketSet(1);
- msglen = strlen(pingmsg) + 1;
+ msglen = strlen(pingmsg) + 1;
memset(recvBuffer, '\0', sizeof(recvBuffer));
AddSocket(socket_set, server_res->socket);
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
+ //--------------------------------------------------------------------------------------
+
// Main game loop
- while (!WindowShouldClose()) {
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ UpdateNetwork();
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
BeginDrawing();
- ClearBackground(RAYWHITE);
- NetworkUpdate();
+
+ ClearBackground(RAYWHITE);
+
+
+
EndDrawing();
+ //----------------------------------------------------------------------------------
}
- // Cleanup
- CloseWindow();
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
return 0;
}
\ No newline at end of file |
