SDLNet_TCP_Send

Name

SDLNet_TCP_Send -- send data on a connected socket.

Synopsis

int SDLNet_TCP_Send(TCPsocket sock, void *data, int len)

sock is a valid, connected, TCPsocket.

data is a pointer to the data that will be sent.

len is the length (in bytes) of the data.

Description

SDLNet_TCP_Send sends the data over the socket. If the data cannot be sent immediately, the routine waits until all of the data may be delivered properly (it is a blocking operation). This routine is not used for server sockets.

Return Value

Returns the number of bytes sent. If the number returned is less than len, an error occured, such as the client disconnecting.

Example

// send a hello over sock
//TCPsocket sock;
int len, result;
char* msg= "Hello!";

len = strlen(msg) + 1; // add one for the terminating NULL
result = SDLNet_TCP_Send(sock,msg,len);
if( result < len ) {
    printf( "SDLNet_TCP_Send: %s\n", SDLNet_GetError() );
    // It may be good to disconnect sock because it is likely invalid now.
}

See Also

SDLNet_TCP_Recv, SDLNet_TCP_Accept, SDLNet_TCP_Open, SDLNet_TCP_GetPeerAddress, SDLNet_TCP_Close, TCPsocket

SDLNet_TCP_Send (last edited 2008-04-17 08:18:48 by localhost)