Remove trail spaces
This commit is contained in:
parent
f92ee46d86
commit
dcf52c132f
61 changed files with 565 additions and 565 deletions
|
@ -40,16 +40,16 @@ static void NetworkConnect(void)
|
|||
{
|
||||
ping = true;
|
||||
connected = true;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the client is connected, run the server code to check for a connection
|
||||
if (clientConnected)
|
||||
if (clientConnected)
|
||||
{
|
||||
int active = CheckSockets(socketSet, 0);
|
||||
if (active != 0) TraceLog(LOG_INFO, "There are currently %d socket(s) with data to be processed.", active);
|
||||
|
||||
if (active > 0)
|
||||
if (active > 0)
|
||||
{
|
||||
if ((connection = SocketAccept(serverResult->socket, &connectionConfig)) != NULL)
|
||||
{
|
||||
|
@ -58,7 +58,7 @@ static void NetworkConnect(void)
|
|||
ping = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if we're connected every _delay_ seconds
|
||||
|
@ -66,7 +66,7 @@ static void NetworkConnect(void)
|
|||
if (elapsed > delay)
|
||||
{
|
||||
if (IsSocketConnected(clientResult->socket)) clientConnected = true;
|
||||
|
||||
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ static void UpdateNetwork(void)
|
|||
{
|
||||
if (IsSocketReady(clientResult->socket)) bytesRecv = SocketReceive(clientResult->socket, receiveBuffer, msglen);
|
||||
if (IsSocketReady(serverResult->socket)) bytesRecv = SocketReceive(serverResult->socket, receiveBuffer, msglen);
|
||||
}
|
||||
}
|
||||
else if (IsSocketReady(connection)) bytesRecv = SocketReceive(connection, receiveBuffer, msglen);
|
||||
|
||||
// If we received data, was that data a "Ping!" or a "Pong!"
|
||||
|
@ -107,14 +107,14 @@ static void UpdateNetwork(void)
|
|||
ping = false;
|
||||
if (serverConfig.type == SOCKET_UDP && clientConfig.type == SOCKET_UDP) SocketSend(clientResult->socket, pingmsg, msglen);
|
||||
else SocketSend(clientResult->socket, pingmsg, msglen);
|
||||
}
|
||||
}
|
||||
else if (pong)
|
||||
{
|
||||
pong = false;
|
||||
if (serverConfig.type == SOCKET_UDP && clientConfig.type == SOCKET_UDP) SocketSend(clientResult->socket, pongmsg, msglen);
|
||||
else SocketSend(clientResult->socket, pongmsg, msglen);
|
||||
}
|
||||
|
||||
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ int main(void)
|
|||
|
||||
// Create the server: getaddrinfo + socket + setsockopt + bind + listen
|
||||
serverResult = LoadSocketResult();
|
||||
if (!SocketCreate(&serverConfig, serverResult))
|
||||
if (!SocketCreate(&serverConfig, serverResult))
|
||||
{
|
||||
TraceLog(LOG_WARNING, "Failed to open server: status %d, errno %d", serverResult->status, serverResult->socket->status);
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ int main(void)
|
|||
if (!SocketBind(&serverConfig, serverResult))
|
||||
{
|
||||
TraceLog(LOG_WARNING, "Failed to bind server: status %d, errno %d", serverResult->status, serverResult->socket->status);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(serverConfig.type == SOCKET_UDP))
|
||||
|
@ -156,7 +156,7 @@ int main(void)
|
|||
|
||||
// Create the client: getaddrinfo + socket + setsockopt + connect (TCP only)
|
||||
clientResult = LoadSocketResult();
|
||||
if (!SocketCreate(&clientConfig, clientResult))
|
||||
if (!SocketCreate(&clientConfig, clientResult))
|
||||
{
|
||||
TraceLog(LOG_WARNING, "Failed to open client: status %d, errno %d", clientResult->status, clientResult->socket->status);
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ int main(void)
|
|||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
// TODO: Draw relevant connection info
|
||||
|
||||
EndDrawing();
|
||||
|
@ -204,7 +204,7 @@ int main(void)
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseNetworkDevice(); // Close network communication
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -22,17 +22,17 @@ int main(void)
|
|||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [network] example - resolve host");
|
||||
|
||||
|
||||
InitNetworkDevice(); // Init network communications
|
||||
|
||||
|
||||
char buffer[ADDRESS_IPV6_ADDRSTRLEN];
|
||||
unsigned short port = 0;
|
||||
|
||||
AddressInformation *address = LoadAddressList(1);
|
||||
|
||||
|
||||
// Address info flags
|
||||
// ADDRESS_INFO_NUMERICHOST // or try them in conjunction to
|
||||
// ADDRESS_INFO_NUMERICSERV // specify custom behaviour from
|
||||
// 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
|
||||
|
@ -70,7 +70,7 @@ int main(void)
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseNetworkDevice(); // Close network communication
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -24,10 +24,10 @@ int main(void)
|
|||
InitWindow(screenWidth, screenHeight, "raylib [network] example - tcp client");
|
||||
|
||||
InitNetworkDevice(); // Init network communications
|
||||
|
||||
|
||||
const char *pingmsg = "Ping!";
|
||||
const char *pongmsg = "Pong!";
|
||||
|
||||
|
||||
bool ping = false;
|
||||
bool pong = false;
|
||||
float elapsed = 0.0f;
|
||||
|
@ -35,12 +35,12 @@ int main(void)
|
|||
bool connected = false;
|
||||
|
||||
SocketConfig clientConfig = {
|
||||
.host = "127.0.0.1",
|
||||
.port = "4950",
|
||||
.type = SOCKET_TCP,
|
||||
.host = "127.0.0.1",
|
||||
.port = "4950",
|
||||
.type = SOCKET_TCP,
|
||||
.nonblocking = true
|
||||
};
|
||||
|
||||
|
||||
SocketSet *socketSet = NULL;
|
||||
SocketResult *clientResult = NULL;
|
||||
char receiveBuffer[512] = { 0 };
|
||||
|
@ -48,9 +48,9 @@ int main(void)
|
|||
// Create the client: getaddrinfo + socket + setsockopt + connect (TCP only)
|
||||
clientResult = LoadSocketResult();
|
||||
if (!SocketCreate(&clientConfig, clientResult)) TraceLog(LOG_WARNING, "Failed to open client: status %d, errno %d", clientResult->status, clientResult->socket->status);
|
||||
else
|
||||
else
|
||||
{
|
||||
if (!(clientConfig.type == SOCKET_UDP))
|
||||
if (!(clientConfig.type == SOCKET_UDP))
|
||||
{
|
||||
if (!SocketConnect(&clientConfig, clientResult)) TraceLog(LOG_WARNING, "Failed to connect to server: status %d, errno %d", clientResult->status, clientResult->socket->status);
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ int main(void)
|
|||
if (IsSocketReady(clientResult->socket)) bytesRecv = SocketReceive(clientResult->socket, receiveBuffer, (int)strlen(pingmsg) + 1);
|
||||
|
||||
// If we received data, was that data a "Ping!" or a "Pong!"
|
||||
if (bytesRecv > 0)
|
||||
if (bytesRecv > 0)
|
||||
{
|
||||
if (strcmp(receiveBuffer, pingmsg) == 0) { pong = true; }
|
||||
if (strcmp(receiveBuffer, pongmsg) == 0) { ping = true; }
|
||||
|
@ -91,19 +91,19 @@ int main(void)
|
|||
|
||||
// After each delay has expired, send a response "Ping!" for a "Pong!" and vice versa
|
||||
elapsed += GetFrameTime();
|
||||
if (elapsed > delay)
|
||||
if (elapsed > delay)
|
||||
{
|
||||
if (ping)
|
||||
if (ping)
|
||||
{
|
||||
ping = false;
|
||||
SocketSend(clientResult->socket, pingmsg, (int)strlen(pingmsg) + 1);
|
||||
}
|
||||
else if (pong)
|
||||
else if (pong)
|
||||
{
|
||||
pong = false;
|
||||
SocketSend(clientResult->socket, pongmsg, (int)strlen(pingmsg) + 1);
|
||||
}
|
||||
|
||||
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ int main(void)
|
|||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
// TODO: Draw relevant connection info
|
||||
|
||||
EndDrawing();
|
||||
|
@ -134,7 +134,7 @@ int main(void)
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseNetworkDevice(); // Close network communication
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -24,10 +24,10 @@ int main(void)
|
|||
InitWindow(screenWidth, screenHeight, "raylib [network] example - tcp server");
|
||||
|
||||
InitNetworkDevice(); // Init network communications
|
||||
|
||||
|
||||
const char *pingmsg = "Ping!";
|
||||
const char *pongmsg = "Pong!";
|
||||
|
||||
|
||||
bool ping = false;
|
||||
bool pong = false;
|
||||
float elapsed = 0.0f;
|
||||
|
@ -35,32 +35,32 @@ int main(void)
|
|||
bool connected = false;
|
||||
|
||||
SocketConfig serverConfig = {
|
||||
.host = "127.0.0.1",
|
||||
.port = "4950",
|
||||
.host = "127.0.0.1",
|
||||
.port = "4950",
|
||||
.type = SOCKET_TCP,
|
||||
.server = true,
|
||||
.nonblocking = true
|
||||
};
|
||||
|
||||
|
||||
SocketConfig connectionConfig = { .nonblocking = true };
|
||||
|
||||
|
||||
Socket *connection = NULL;
|
||||
SocketSet *socketSet = NULL;
|
||||
SocketResult *serverResult = NULL;
|
||||
char receiveBuffer[512] = { 0 };
|
||||
|
||||
|
||||
// Create the server: getaddrinfo + socket + setsockopt + bind + listen
|
||||
serverResult = LoadSocketResult();
|
||||
if (!SocketCreate(&serverConfig, serverResult))
|
||||
if (!SocketCreate(&serverConfig, serverResult))
|
||||
{
|
||||
TraceLog(LOG_WARNING, "Failed to open server: status %d, errno %d", serverResult->status, serverResult->socket->status);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!SocketBind(&serverConfig, serverResult))
|
||||
{
|
||||
TraceLog(LOG_WARNING, "Failed to bind server: status %d, errno %d", serverResult->status, serverResult->socket->status);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(serverConfig.type == SOCKET_UDP))
|
||||
|
@ -107,17 +107,17 @@ int main(void)
|
|||
elapsed += GetFrameTime();
|
||||
if (elapsed > delay)
|
||||
{
|
||||
if (ping)
|
||||
if (ping)
|
||||
{
|
||||
ping = false;
|
||||
SocketSend(connection, pingmsg, (int)strlen(pingmsg) + 1);
|
||||
}
|
||||
}
|
||||
else if (pong)
|
||||
{
|
||||
pong = false;
|
||||
SocketSend(connection, pongmsg, (int)strlen(pingmsg) + 1);
|
||||
}
|
||||
|
||||
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
}
|
||||
|
@ -127,9 +127,9 @@ int main(void)
|
|||
int active = CheckSockets(socketSet, 0);
|
||||
if (active != 0) TraceLog(LOG_DEBUG, "There are currently %d socket(s) with data to be processed.", active);
|
||||
|
||||
if (active > 0)
|
||||
if (active > 0)
|
||||
{
|
||||
if ((connection = SocketAccept(serverResult->socket, &connectionConfig)) != NULL)
|
||||
if ((connection = SocketAccept(serverResult->socket, &connectionConfig)) != NULL)
|
||||
{
|
||||
AddSocket(socketSet, connection);
|
||||
connected = true;
|
||||
|
@ -144,7 +144,7 @@ int main(void)
|
|||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
// TODO: Draw relevant connection info
|
||||
|
||||
EndDrawing();
|
||||
|
@ -154,7 +154,7 @@ int main(void)
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseNetworkDevice(); // Close network communication
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ void test_resolve_host()
|
|||
const char *address = "localhost";
|
||||
const char *port = "80";
|
||||
AddressInformation *addr = LoadAddressList(3);
|
||||
int count = ResolveHost(address, port, ADDRESS_TYPE_ANY, 0, addr);
|
||||
int count = ResolveHost(address, port, ADDRESS_TYPE_ANY, 0, addr);
|
||||
|
||||
assert(GetAddressFamily(addr[0]) == ADDRESS_TYPE_IPV6);
|
||||
assert(GetAddressFamily(addr[1]) == ADDRESS_TYPE_IPV4);
|
||||
|
@ -122,9 +122,9 @@ int main(void)
|
|||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [network] example - network test");
|
||||
|
||||
|
||||
InitNetworkDevice(); // Init network communications
|
||||
|
||||
|
||||
// Run some tests
|
||||
test_resolve_host();
|
||||
//test_socket_create();
|
||||
|
@ -146,7 +146,7 @@ int main(void)
|
|||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
// TODO: Draw relevant connection info
|
||||
|
||||
EndDrawing();
|
||||
|
@ -156,7 +156,7 @@ int main(void)
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseNetworkDevice(); // Close network communication
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -24,22 +24,22 @@ int main(void)
|
|||
InitWindow(screenWidth, screenHeight, "raylib [network] example - udp client");
|
||||
|
||||
InitNetworkDevice(); // Init network communications
|
||||
|
||||
|
||||
const char *pingmsg = "Ping!";
|
||||
const char *pongmsg = "Pong!";
|
||||
|
||||
|
||||
bool ping = true;
|
||||
bool pong = false;
|
||||
float elapsed = 0.0f;
|
||||
float delay = 1.0f;
|
||||
|
||||
SocketConfig clientConfig = {
|
||||
.host = "127.0.0.1",
|
||||
.port = "4950",
|
||||
.type = SOCKET_UDP,
|
||||
.host = "127.0.0.1",
|
||||
.port = "4950",
|
||||
.type = SOCKET_UDP,
|
||||
.nonblocking = true
|
||||
};
|
||||
|
||||
|
||||
SocketResult *clientResult = NULL;
|
||||
SocketSet *socketSet = NULL;
|
||||
char receiveBuffer[512] = { 0 };
|
||||
|
@ -76,7 +76,7 @@ int main(void)
|
|||
if (IsSocketReady(clientResult->socket)) bytesRecv = SocketReceive(clientResult->socket, receiveBuffer, (int)strlen(pingmsg) + 1);
|
||||
|
||||
// If we received data, was that data a "Ping!" or a "Pong!"
|
||||
if (bytesRecv > 0)
|
||||
if (bytesRecv > 0)
|
||||
{
|
||||
if (strcmp(receiveBuffer, pingmsg) == 0) { pong = true; }
|
||||
if (strcmp(receiveBuffer, pongmsg) == 0) { ping = true; }
|
||||
|
@ -86,17 +86,17 @@ int main(void)
|
|||
elapsed += GetFrameTime();
|
||||
if (elapsed > delay)
|
||||
{
|
||||
if (ping)
|
||||
if (ping)
|
||||
{
|
||||
ping = false;
|
||||
SocketSend(clientResult->socket, pingmsg, (int)strlen(pingmsg) + 1);
|
||||
}
|
||||
}
|
||||
else if (pong)
|
||||
{
|
||||
pong = false;
|
||||
SocketSend(clientResult->socket, pongmsg, (int)strlen(pongmsg) + 1);
|
||||
}
|
||||
|
||||
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -106,7 +106,7 @@ int main(void)
|
|||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
// TODO: Draw relevant connection info
|
||||
|
||||
EndDrawing();
|
||||
|
@ -116,7 +116,7 @@ int main(void)
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseNetworkDevice(); // Close network communication
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -24,30 +24,30 @@ int main(void)
|
|||
InitWindow(screenWidth, screenHeight, "raylib [network] example - udp server");
|
||||
|
||||
InitNetworkDevice(); // Init network communications
|
||||
|
||||
|
||||
const char *pingmsg = "Ping!";
|
||||
const char *pongmsg = "Pong!";
|
||||
|
||||
|
||||
bool ping = false;
|
||||
bool pong = false;
|
||||
float elapsed = 0.0f;
|
||||
float delay = 1.0f;
|
||||
|
||||
SocketConfig serverConfig = {
|
||||
.host = "127.0.0.1",
|
||||
.port = "4950",
|
||||
.server = true,
|
||||
.type = SOCKET_UDP,
|
||||
.host = "127.0.0.1",
|
||||
.port = "4950",
|
||||
.server = true,
|
||||
.type = SOCKET_UDP,
|
||||
.nonblocking = true
|
||||
};
|
||||
|
||||
|
||||
SocketResult *serverResult = NULL;
|
||||
SocketSet *socketSet = NULL;
|
||||
char receiveBuffer[512] = { 0 };
|
||||
|
||||
// Create the server: getaddrinfo + socket + setsockopt + bind + listen
|
||||
serverResult = LoadSocketResult();
|
||||
|
||||
|
||||
if (!SocketCreate(&serverConfig, serverResult)) TraceLog(LOG_WARNING, "Failed to open server: status %d, errno %d", serverResult->status, serverResult->socket->status);
|
||||
else if (!SocketBind(&serverConfig, serverResult)) TraceLog(LOG_WARNING, "Failed to bind server: status %d, errno %d", serverResult->status, serverResult->socket->status);
|
||||
|
||||
|
@ -65,7 +65,7 @@ int main(void)
|
|||
//----------------------------------------------------------------------------------
|
||||
// Once connected to the network, check the sockets for pending information
|
||||
// and when information is ready, send either a Ping or a Pong.
|
||||
|
||||
|
||||
// CheckSockets, if any of the sockets in the set are pending (received data, or requests)
|
||||
// then mark the socket as being ready. You can check this with IsSocketReady(client_res->socket)
|
||||
int active = CheckSockets(socketSet, 0);
|
||||
|
@ -79,7 +79,7 @@ int main(void)
|
|||
int bytesRecv = SocketReceive(serverResult->socket, receiveBuffer, (int)strlen(pingmsg) + 1);
|
||||
|
||||
// If we received data, is that data a "Ping!" or a "Pong!"?
|
||||
if (bytesRecv > 0)
|
||||
if (bytesRecv > 0)
|
||||
{
|
||||
if (strcmp(receiveBuffer, pingmsg) == 0) { pong = true; }
|
||||
if (strcmp(receiveBuffer, pongmsg) == 0) { ping = true; }
|
||||
|
@ -87,20 +87,20 @@ int main(void)
|
|||
|
||||
// After each delay has expired, send a response "Ping!" for a "Pong!" and vice-versa
|
||||
elapsed += GetFrameTime();
|
||||
|
||||
|
||||
if (elapsed > delay)
|
||||
{
|
||||
if (ping)
|
||||
if (ping)
|
||||
{
|
||||
ping = false;
|
||||
SocketSend(serverResult->socket, pingmsg, (int)strlen(pingmsg) + 1);
|
||||
}
|
||||
else if (pong)
|
||||
}
|
||||
else if (pong)
|
||||
{
|
||||
pong = false;
|
||||
SocketSend(serverResult->socket, pongmsg, (int)strlen(pongmsg) + 1);
|
||||
}
|
||||
|
||||
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -120,7 +120,7 @@ int main(void)
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseNetworkDevice(); // Close network communication
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue