NET_AcceptClient(3)
β¨ NET_AcceptClient(3) β¨
okay bestie, welcome to the SDL_net3 manual, page NET_AcceptClient π this is where your server finally stops ghosting all the clients knocking on its door.
πΈ NAME πΈ
NET_AcceptClient β create a stream socket for the next pending client connection. it's giving "yes queen, come in" π
π SYNOPSIS π
#include <SDL3_net/SDL_net.h>
bool NET_AcceptClient(NET_Server *server, NET_StreamSocket **client_stream);
π¦ DESCRIPTION π¦
so here's the tea, fr fr: when a client connects to a server, their connection just... sits there. pending. waiting. π It stays pending until the server accepts the connection. Once it's accepted, the server gets handed a stream socket to talk to that client with, and from then on they can send data to each other and receive data from each other. mutuals!! π«Ά
unlike NET_CreateClient, the stream sockets you get back from this function are already connected β you do NOT have to sit around waiting for the connection to finish, because server acceptance is literally the final step of connecting. no loading screen, no vibe check pending, it's done. β¨
This function does not block. So if there are no new connections pending, it will return true (for success, but *client_stream will be set to NULL. That is not an error β it's a super common condition that your app should expect. In fact, you should call this function in a loop until that condition happens, so that all the pending connections get accepted in a single batch. one sweep, all the besties. π
If you do want the server to sleep until there's a new connection, you can use NET_WaitUntilInputAvailable(). π΄
When you're done with the newly-accepted client, you can disconnect and dispose of the stream socket by calling NET_DestroyStreamSocket(). bye babe π
π FUNCTION PARAMETERS π
serverβ the server object to check for pending connections. this is the one doing the vibe check.client_streamβ Will be set to a new stream socket if a connection was pending,NULLotherwise.
π₯ RETURN VALUE π₯
Returns true on success (even if no new connections were pending), false on error; call SDL_GetError() for details. yes, even "nothing happened" counts as success, that's just how she is.
π THREAD SAFETY π
You should not operate on the same server from multiple threads at the same time without supplying a serialization mechanism. no cap, that's a one-bestie-at-a-time situation. π«
However β different threads may access different servers at the same time without problems. everybody gets their own, slay. π
β AVAILABILITY β
This function is available since SDL_net 3.0.0.
π SEE ALSO π
and that's the whole page, babe π§ this was SDL_net manual, version SDL_net 3.2.0, page NET_AcceptClient(3) β go accept some clients, you're literally the main character of this server πβ¨πΈ
π¦ where this page comes from
- fedora 43: SDL3_net-devel 3.2.0-2.fc43 Β· Zlib
- fedora 43: SDL3_net-devel 3.2.0-2.fc43 Β· Zlib
- fedora 44: SDL3_net-devel 3.2.0-2.fc44 Β· Zlib
- fedora 44: SDL3_net-devel 3.2.0-2.fc44 Β· Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms