NET_CreateClient(3)
π NET_CreateClient(3) π
okay bestie, welcome to the SDL_net3 FUNCTIONS corner of the manual, and today's main character is NET_CreateClient π«Ά
β¨ NAME β¨
NET_CreateClient β start connecting a socket as a client to a remote server. it's giving "hi, can we be friends" but with TCP π₯
β¨ SYNOPSIS β¨
#include <SDL3_net/SDL_net.h>
NET_StreamSocket * NET_CreateClient(NET_Address *address, Uint16 port, SDL_PropertiesID props);
β¨ DESCRIPTION β¨
so like, every single NET_StreamSocket is one connection between systems. one. single. connection. usually a client app has one connection to a server app living on some other computer, and that server app might be juggling a whole crowd of connections from different clients π and each of those connections talks over its own separate stream socket. iconic, honestly.
connecting is asynchronous, which is the fancy way of saying: this function does not block, and it will come back to you before the connection is actually complete. so you can't just assume it worked!! you have to go check with NET_WaitUntilConnected() or NET_GetConnectionStatus() to see when the operation finished and whether it was actually successful. no skipping this step, fr fr π
once you're connected, you can read and write data on the socket you got back. stream sockets are a mode of reliable transmission β that means your data shows up as a stream of bytes in the exact order you sent it. if transmission has problems, the system handles protocol negotiation and retransmission for you, transparent to your app, no notes π but here's the tradeoff: until data is available in the order sent, the remote side gets nothing new. that's the deal you make. compare that to datagram sockets, where data can arrive in any order, or just... not arrive at all, without waiting β but the sender never finds out. pick your fighter.
stream sockets don't employ any protocol above the TCP level, so they can connect to servers that aren't even using SDL_net π¦ but if you wanna speak anything beyond an arbitrary stream of bytes β like HTTP β you're gonna have to implement that yourself on top of the stream socket. it's giving DIY. it's giving "you got this, but it's on you."
heads up bestie: this function will fail if address is not finished resolving. π¨
when you're done with this connection β and yes, that includes if it failed to connect β you must dispose of it with NET_DestroyStreamSocket(). don't leave it lying around, that's not the vibe πΈ
and here's a lil gift: unlike BSD sockets or WinSock, you pass the port as a normal integer. you do not have to byteswap it into "network order" β the library handles that for you. periodt π
also, as of right now there are no extra properties for creating a client, so props should be zero. a future revision of SDL_net may add additional (optional) properties though, so keep an eye out π
β¨ FUNCTION PARAMETERS β¨
addressβ the address of the remote server you're connecting to. the destination. the whole point. π―portβ the port on that remote server you're connecting to. πpropsβ the properties of your new client. specify zero for defaults. (and rn zero is literally the only option, so, easy.) β¨
β¨ RETURN VALUE β¨
returns a new NET_StreamSocket with a pending connection, or NULL on error π β and if you get NULL, call SDL_GetError() for the details. always read the error, bestie, it's literally telling you what went wrong.
β¨ THREAD SAFETY β¨
it is safe to call this function from any thread. go wild. π
β¨ AVAILABILITY β¨
this function has been available since SDL_net 3.0.0 π
β¨ SEE ALSO β¨
NET_WaitUntilConnected(3)β go wait for it to connect πNET_GetConnectionStatus(3)β go check how it's going πNET_DestroyStreamSocket(3)β go clean up after yourself π§
and that's the whole page, bestie!! this one's from SDL_net 3.2.0, manual page NET_CreateClient(3), brought to you by the fine folks over at SDL_net π go forth and connect responsibly, mwah π«Άβ¨
π¦ 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