Tao.Sdl SDK Documentation |
|
SdlNet.SDLNet_UDP_GetPeerAddress Method
Get the assigned IP address for a socket channel or get the port you opened the socket with
[Visual Basic]
Public Shared Function SDLNet_UDP_GetPeerAddress( _
ByVal
sock As
IntPtr, _
ByVal
channel As
Integer _
) As
IntPtr
[C#]
public static
IntPtr SDLNet_UDP_GetPeerAddress(
IntPtr sock,
int channel);
Parameters
-
sock
- A valid UDPsocket that probably has an address assigned to the channel.
-
channel
- The channel to get the primary address from in the socket. This may also be -1 to get the port which this socket is bound to on the local computer.
Return Value
a pointer to an IPaddress. NULL is returned for unbound channels and on any errors.
Remarks
Get the primary address assigned to this channel. Only the first bound address is returned. When channel is -1, get the port that this socket is bound to on the local computer, this only means something if you opened the socket with a specific port number. Do not free the returned IPaddress pointer.
Binds to C-function call in SDL_net.h:
extern DECLSPEC IPaddress * SDLCALL SDLNet_UDP_GetPeerAddress(UDPsocket sock, int channel)
Example
// get the primary address bound to UDPsocket channel 0
//UDPsocket udpsock;
//IPaddress *address;
address=SDLNet_UDP_GetPeerAddress(udpsock, 0);
if(!address) {
printf("SDLNet_UDP_GetPeerAddress: %s\n", SDLNet_GetError());
// do something because we failed to get the address
}
else {
// perhaps print out address->host and address->port
}
See Also
SdlNet Class | Tao.Sdl Namespace | SDLNet_UDP_Unbind | SDLNet_UDP_Bind | SdlNet.UDPsocket