SDL Wiki
[ front page | index | search | recent changes | git repo | offline html ]

QuickReference

If you want to paste this into a text editor that can't handle the fancy Unicode section headers, try using QuickReferenceNoUnicode instead.

// SDL3_net API Quick Reference
//
// https://libsdl.org/
//
// The latest version of this document can be found at https://wiki.libsdl.org/SDL3_net/QuickReference
// Based on SDL_net version 3.0.0
//
// This can be useful in an IDE with search and syntax highlighting.
//
// Original idea for this document came from Dan Bechard (thanks!)
// ASCII art generated by: https://patorjk.com/software/taag/#p=display&f=ANSI%20Shadow (with modified 'S' for readability)


//  ██████╗ ██████╗  ██╗      ███╗   ██╗ ███████╗ ████████╗
// ██╔════╝ ██╔══██╗ ██║      ████╗  ██║ ██╔════╝ ╚══██╔══╝
// ███████╗ ██║  ██║ ██║      ██╔██╗ ██║ █████╗      ██║   
// ╚════██║ ██║  ██║ ██║      ██║╚██╗██║ ██╔══╝      ██║   
// ██████╔╝ ██████╔╝ ███████╗ ██║ ╚████║ ███████╗    ██║   
// ╚═════╝  ╚═════╝  ╚══════╝ ╚═╝  ╚═══╝ ╚══════╝    ╚═╝   

#define SDL_NET_MAJOR_VERSION                                                                                     // The current major version of SDL_net headers.
#define SDL_NET_MINOR_VERSION                                                                                     // The current minor version of the SDL_net headers.
#define SDL_NET_MICRO_VERSION                                                                                     // The current micro (or patchlevel) version of the SDL_net headers.
#define SDL_NET_VERSION                                                                                           // This is the version number macro for the current SDL_net version.
#define SDL_NET_VERSION_ATLEAST(X, Y, Z)                                                                          // This macro will evaluate to true if compiled with SDL_net at least X.Y.Z.
int NET_GetVersion(void);                                                                                         // This function gets the version of the dynamically linked SDL_net library.
bool NET_Init(void);                                                                                              // Initialize the SDL_net library.
void NET_Quit(void);                                                                                              // Deinitialize the SDL_net library.
NET_Address * NET_ResolveHostname(const char *host);                                                              // Resolve a human-readable hostname.
int NET_WaitUntilResolved(NET_Address *address, Sint32 timeout);                                                  // Block until an address is resolved.
int NET_GetAddressStatus(NET_Address *address);                                                                   // Check if an address is resolved, without blocking.
const char * NET_GetAddressString(NET_Address *address);                                                          // Get a human-readable string from a resolved address.
NET_Address * NET_RefAddress(NET_Address *address);                                                               // Add a reference to an NET_Address.
void NET_UnrefAddress(NET_Address *address);                                                                      // Drop a reference to an NET_Address.
void NET_SimulateAddressResolutionLoss(int percent_loss);                                                         // Enable simulated address resolution failures.
int NET_CompareAddresses(const NET_Address *a, const NET_Address *b);                                             // Compare two NET_Address objects.
NET_Address ** NET_GetLocalAddresses(int *num_addresses);                                                         // Obtain a list of local addresses on the system.
void NET_FreeLocalAddresses(NET_Address **addresses);                                                             // Free the results from NET_GetLocalAddresses.
NET_StreamSocket * NET_CreateClient(NET_Address *address, Uint16 port);                                           // Begin connecting a socket as a client to a remote server.
int NET_WaitUntilConnected(NET_StreamSocket *sock, Sint32 timeout);                                               // Block until a stream socket has connected to a server.
NET_Server * NET_CreateServer(NET_Address *addr, Uint16 port);                                                    // Create a server, which listens for connections to accept.
bool NET_AcceptClient(NET_Server *server, NET_StreamSocket **client_stream);                                      // Create a stream socket for the next pending client connection.
void NET_DestroyServer(NET_Server *server);                                                                       // Dispose of a previously-created server.
NET_Address * NET_GetStreamSocketAddress(NET_StreamSocket *sock);                                                 // Get the remote address of a stream socket.
int NET_GetConnectionStatus(NET_StreamSocket *sock);                                                              // Check if a stream socket is connected, without blocking.
bool NET_WriteToStreamSocket(NET_StreamSocket *sock, const void *buf, int buflen);                                // Send bytes over a stream socket to a remote system.
int NET_GetStreamSocketPendingWrites(NET_StreamSocket *sock);                                                     // Query bytes still pending transmission on a stream socket.
int NET_WaitUntilStreamSocketDrained(NET_StreamSocket *sock, Sint32 timeout);                                     // Block until all of a stream socket's pending data is sent.
int NET_ReadFromStreamSocket(NET_StreamSocket *sock, void *buf, int buflen);                                      // Receive bytes that a remote system sent to a stream socket.
void NET_SimulateStreamPacketLoss(NET_StreamSocket *sock, int percent_loss);                                      // Enable simulated stream socket failures.
void NET_DestroyStreamSocket(NET_StreamSocket *sock);                                                             // Dispose of a previously-created stream socket.
NET_DatagramSocket * NET_CreateDatagramSocket(NET_Address *addr, Uint16 port);                                    // Create and bind a new datagram socket.
bool NET_SendDatagram(NET_DatagramSocket *sock, NET_Address *address, Uint16 port, const void *buf, int buflen);  // Send a new packet over a datagram socket to a remote system.
bool NET_ReceiveDatagram(NET_DatagramSocket *sock, NET_Datagram **dgram);                                         // Receive a new packet that a remote system sent to a datagram socket.
void NET_DestroyDatagram(NET_Datagram *dgram);                                                                    // Dispose of a datagram packet previously received.
void NET_SimulateDatagramPacketLoss(NET_DatagramSocket *sock, int percent_loss);                                  // Enable simulated datagram socket failures.
void NET_DestroyDatagramSocket(NET_DatagramSocket *sock);                                                         // Dispose of a previously-created datagram socket.
int NET_WaitUntilInputAvailable(void **vsockets, int numsockets, Sint32 timeout);                                 // Block on multiple sockets until at least one has data available.

[ edit | delete | history | feedback | raw ]

All wiki content is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).
Wiki powered by ghwikipp.