Receive data from a non-server socket.
Defined in <SDL_net.h>
int SDLNet_TCP_Recv(TCPsocket sock, void *data, int maxlen);
TCPsocket | sock | the socket to send data to. |
void * | data | a pointer to where to store received data. |
int | maxlen | the maximum number of bytes that can be stored at data . |
(int) Returns number of bytes received, which might be less than maxlen
.
sock
must be a valid socket that was created by SDLNet_TCP_Open with a specific address, or SDLNet_TCP_Accept.
Receive up to maxlen
bytes of data over the non-server socket sock
, and store them in the buffer pointed to by data
.
This function returns the actual amount of data received. If the return value is less than or equal to zero, then either the remote connection was closed, or an unknown socket error occurred.
Note that this will return the number of bytes available at the first moment the socket is able to see new data. If packets are coming in slowly from the network, this might be less data than you expect at a given time.
This function may block! Use SDLNet_CheckSockets() to make sure there is data available before calling this function, if you want to avoid blocking.
This function is available since SDL_net 2.0.0.