[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.4.6 SDLNet_UDP_Send

int SDLNet_UDP_Send(UDPsocket sock, int channel, UDPpacket *packet)

sock
A valid UDPsocket.
channel
what channel to send packet on.
packet
The packet to send.

Send packet using the specified socket sock, use ing the specified channel or else the packet's address.
If channel is not -1 then the packet is sent to all the socket channels bound addresses. If socket sock's channel is not bound to any destinations, then the packet is not sent at all!
If the channel is -1, then the packet's address is used as the destination.
Don't forget to set the length of the packet in the len element of the packet you are sending! Note: the packet->channel will be set to the channel passed in to this function. Note: The maximum size of the packet is limited by the MTU (Maximum Transfer Unit) of the transport medium. It can be as low as 250 bytes for some PPP links, and as high as 1500 bytes for ethernet. Beyond that limit the packet will fragment, and make delivery more and more unreliable as lost fragments cause the whole packet to be discarded.

Returns: 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.

 
// 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...
}

See Also:
3.4.3 SDLNet_UDP_Bind, 3.4.8 SDLNet_UDP_SendV, 3.4.7 SDLNet_UDP_Recv, 3.4.9 SDLNet_UDP_RecvV, 4.4 UDPpacket, 4.3 UDPsocket


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on November, 3 2009 using texi2html