more example stubs
more changes to rnet i'm tired, it's 2am why am i doing this
This commit is contained in:
parent
bde0b6cd75
commit
ee85f59643
1 changed files with 1774 additions and 423 deletions
|
|
@ -25,7 +25,7 @@
|
|||
int main()
|
||||
{
|
||||
// Setup
|
||||
int screenWidth = 800;
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
InitWindow(
|
||||
screenWidth, screenHeight, "raylib [network] example - ping pong");
|
||||
|
|
@ -38,23 +38,26 @@ int main()
|
|||
|
||||
// Create the server
|
||||
SocketConfig server_cfg = {
|
||||
.host = "127.0.0.1",
|
||||
.port = 8080,
|
||||
.server = true,
|
||||
.nonblocking = true,
|
||||
.host = "127.0.0.1",
|
||||
.port = "8080",
|
||||
.server = true,
|
||||
.nonblocking = true
|
||||
};
|
||||
|
||||
SocketResult server_res;
|
||||
memset(&server_res, 0, sizeof(SocketResult));
|
||||
{
|
||||
bool ok = SocketOpen(&server_cfg, &server_res);
|
||||
if (!ok) { return false; }
|
||||
if (!ok)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Create the client
|
||||
SocketConfig client_cfg = {
|
||||
.host = "127.0.0.1",
|
||||
.port = 8080,
|
||||
.host = "127.0.0.1",
|
||||
.port = "8080"
|
||||
};
|
||||
|
||||
SocketResult client_res;
|
||||
|
|
@ -63,8 +66,8 @@ int main()
|
|||
bool ok = SocketOpen(&client_cfg, &client_res);
|
||||
if (!ok)
|
||||
{
|
||||
printf("failed to open: status %d, errno %d\n",
|
||||
client_res.status, client_res.saved_errno);
|
||||
printf("failed to open: status %d, errno %d\n", client_res.status,
|
||||
client_res.socket.error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -76,6 +79,8 @@ int main()
|
|||
char recvBuffer[512];
|
||||
bool connected = false;
|
||||
memset(&recvBuffer, 0, 8);
|
||||
char pingmsg[6] = "Ping!";
|
||||
char pongmsg[6] = "Pong!";
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose())
|
||||
|
|
@ -91,7 +96,7 @@ int main()
|
|||
{
|
||||
if (SocketAccept(server_res.socket.handle, &connection))
|
||||
{
|
||||
ping = true;
|
||||
ping = true;
|
||||
connected = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -99,18 +104,18 @@ int main()
|
|||
// Connected
|
||||
if (connected)
|
||||
{
|
||||
int bytesRecv = SocketReceive(&connection.socket, recvBuffer, 5);
|
||||
int bytesRecv = SocketReceive(&connection.socket, recvBuffer, sizeof(pingmsg));
|
||||
if (bytesRecv > 0)
|
||||
{
|
||||
if (strcmp(recvBuffer, "Ping!") == 0)
|
||||
if (strcmp(recvBuffer, pingmsg) == 0)
|
||||
{
|
||||
pong = true;
|
||||
printf("Ping!\n");
|
||||
printf("%s\n", pingmsg);
|
||||
}
|
||||
if (strcmp(recvBuffer, "Pong!") == 0)
|
||||
if (strcmp(recvBuffer, pongmsg) == 0)
|
||||
{
|
||||
ping = true;
|
||||
printf("Pong!\n");
|
||||
printf("%s\n", pongmsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -120,12 +125,12 @@ int main()
|
|||
if (ping)
|
||||
{
|
||||
ping = false;
|
||||
SocketSend(&client_res.socket, "Ping!", 5);
|
||||
SocketSend(&client_res.socket, pingmsg, sizeof(pingmsg));
|
||||
}
|
||||
else if (pong)
|
||||
{
|
||||
pong = false;
|
||||
SocketSend(&client_res.socket, "Pong!", 5);
|
||||
SocketSend(&client_res.socket, pongmsg, sizeof(pongmsg));
|
||||
}
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue