Tao.Sdl SDK Documentation |
|
SdlNet.SDLNet_UDP_Recv Method
Receive into a UDPpacket
[Visual Basic]
Public Shared Function SDLNet_UDP_Recv( _
ByVal
sock As
IntPtr, _
ByVal
packet As
IntPtr _
) As
Integer
Parameters
-
sock
- A valid UDPsocket.
-
packet
- The packet to receive into.
Return Value
1 is returned when a packet is received. 0 is returned when no packets are received. -1 is returned on errors.
Remarks
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.
Binds to C-function call in SDL_net.h:
extern DECLSPEC int SDLCALL SDLNet_UDP_Recv(UDPsocket sock, UDPpacket *packet)
Example
// try to receive some waiting udp packets
//UDPsocket udpsock;
//UDPpacket packet;
int numrecv;
numrecv=SDLNet_UDP_Recv(udpsock, &packet);
if(numrecv) {
// do something with packet
}
See Also
SdlNet Class | Tao.Sdl Namespace | SDLNet_UDP_Bind | SDLNet_UDP_Send | SDLNet_UDP_SendV | SDLNet_UDP_RecvV | SdlNet.UDPpacket | SdlNet.UDPsocket