Send a UDPpacket
The number of destinations sent to that worked. 0 is returned on errors.Note that since a channel can point to multiple destinations, there should be just as many packets sent, so dont assume it will always return 1 on success. Unfortunately there's no way to get the number of destinations bound to a channel, so either you have to remember the number bound, or just test for the zero return value indicating all channels failed.
Binds to C-function call in SDL_net.h:
extern DECLSPEC int SDLCALL SDLNet_UDP_Send(UDPsocket sock, int channel, UDPpacket *packet)
// send a packet using a UDPsocket, using the packet's channel as the channel //UDPsocket udpsock; //UDPpacket *packet; int numsent; numsent=SDLNet_UDP_Send(udpsock, packet->channel, packet); if(!numsent) { printf("SDLNet_UDP_Send: %s\n", SDLNet_GetError()); // do something because we failed to send // this may just be because no addresses are bound to the channel... }Here's a way of sending one packet using it's internal channel setting. This is actually what SDLNet_UDP_Send ends up calling for you.
// send a packet using a UDPsocket, using the packet's channel as the channel //UDPsocket udpsock; //UDPpacket *packet; int numsent; numsent=SDLNet_UDP_SendV(sock, &packet, 1); if(!numsent) { printf("SDLNet_UDP_SendV: %s\n", SDLNet_GetError()); // do something because we failed to send // this may just be because no addresses are bound to the channel... }
SdlNet Class | Tao.Sdl Namespace | SDLNet_UDP_Bind | SDLNet_UDP_SendV | SDLNet_UDP_Recv | SDLNet_UDP_RecvV | SdlNet.UDPpacket | SdlNet.UDPsocket