SDLNet_UDP_Recv

Name

SDLNet_UDP_Recv -- recieve a UDP packet.

Synopsis

int SDLNet_UDP_Recv(UDPsocket sock, UDPpacket *packet)

sock A valid UDPsocket.

packet The packet to receive into.

Description

Receive a packet on the specified sock socket.

The packet you pass in must have enough of a data size allocated for the incoming packet data to fit into. This means you should have knowledge of your size needs before trying to receive UDP packets. The packet will have it's address set to the remote sender's address.

The socket`s channels are checked in highest to lowest order, so if an address is bound to multiple channels, the highest channel with the source address bound will be retreived before the lower bound channels. So, the packets channel will also be set to the highest numbered channel that has the remote address and port assigned to it. Otherwise the channel will -1, which you can filter out easily if you want to ignore unbound source address.

Note that the local and remote channel numbers do not have to, and probably won't, match, as they are only local settings, they are not sent in the packet.

This is a non-blocking call, meaning if there's no data ready to be received the function will return.

Return Value

Returns: 1 is returned when a packet is received. 0 is returned when no packets are received. -1 is returned on errors.

Example

// try to receive a waiting udp packet
UDPsocket udpsock;
UDPpacket packet;
int numrecv;

numrecv=SDLNet_UDP_Recv(udpsock, &packet);
if(numrecv) {
    // do something with packet
}

See Also

SDLNet_UDP_Bind, SDLNet_UDP_Send, SDLNet_UDP_SendV, SDLNet_UDP_RecvV, UDPpacket, UDPsocket

SDLNet_UDP_Recv (last edited 2008-04-17 08:18:31 by localhost)