Tao.Sdl SDK Documentation

SdlNet.SDLNet_UDP_Bind Method 

Assign an IP address number to a socket channel

[Visual Basic]
Public Shared Function SDLNet_UDP_Bind( _
   ByVal sock As IntPtr, _
   ByVal channel As Integer, _
   ByRef address As IPaddress _
) As Integer
[C#]
public static int SDLNet_UDP_Bind(
   IntPtr sock,
   int channel,
   ref IPaddress address
);

Parameters

sock
the UDPsocket on which to assign the address.
channel
The channel to assign address to. This should be less than SDLNET_MAX_UDPCHANNELS. If -1 is used, then the first unbound channel will be used, this should only be used for incomming packet filtering, as it will find the first channel with less than SDLNET_MAX_UDPADDRESSES assigned to it and use that one.
address
The resolved IPaddress to assign to the socket's channel. The host and port are both used. It is not helpful to bind 0.0.0.0 to a channel.

Return Value

The channel number that was bound. -1 is returned on errors, such as no free channels, or this channel has SDLNET_MAX_UDPADDRESSES already assigned to it, or you have used a channel higher or equal to SDLNET_MAX_UDPCHANNELS, or lower than -1.

Remarks

Bind an address to a channel on a socket. Incoming packets are only allowed from bound addresses for the socket channel. All outgoing packets on that channel, regardless of the packets internal address, will attempt to send once on each bound address on that channel. You may assign up to SDLNET_MAX_UDPADDRESSES to each channel.

Binds to C-function call in SDL_net.h:

                extern DECLSPEC int SDLCALL SDLNet_UDP_Bind(UDPsocket sock, int channel, IPaddress *address)
            

Example

            // Bind address to the first free channel
            //UDPsocket udpsock;
            //IPaddress *address;
            int channel;
            channel=SDLNet_UDP_Bind(udpsock, -1, address);
            if(channel==-1) {
            printf("SDLNet_UDP_Bind: %s\n", SDLNet_GetError());
            // do something because we failed to bind
            }
            

See Also

SdlNet Class | Tao.Sdl Namespace | SDLNet_UDP_Unbind | SDLNet_UDP_GetPeerAddress | SDLNet_UDP_Open | SdlNet.IPaddress | SdlNet.UDPsocket