Tao.Sdl SDK Documentation

SdlNet.SDLNet_CheckSockets Method 

Check and wait for sockets in a set to have activity

[Visual Basic]
Public Shared Function SDLNet_CheckSockets( _
   ByVal set As SDLNet_SocketSet, _
   ByVal timeout As Integer _
) As Integer
[C#]
public static int SDLNet_CheckSockets(
   SDLNet_SocketSet set,
   int timeout
);

Parameters

set
The socket set to check
timeout
The amount of time (in milliseconds). 0 means no waiting. -1 means to wait over 49 days! (think about it)

Return Value

the number of sockets with activity. -1 is returned on errors, and you may not get a meaningful error message. -1 is also returned for an empty set (nothing to check).

Remarks

Check all sockets in the socket set for activity. If a non-zero timeout is given then this function will wait for activity, or else it will wait for timeout milliseconds. NOTE: "activity" also includes disconnections and other errors, which would be determined by a failed read/write attempt.

Binds to C-function call in SDL_net.h:

            extern DECLSPEC int SDLCALL SDLNet_CheckSockets(SDLNet_SocketSet set, Uint32 timeout)
            

Example

            // Wait for up to 1 second for network activity
            //SDLNet_SocketSet set;
            int numready;
            numready=SDLNet_CheckSockets(set, 1000);
            if(numready==-1) {
            printf("SDLNet_CheckSockets: %s\n", SDLNet_GetError());
            //most of the time this is a system error, where perror might help you.
            perror("SDLNet_CheckSockets");
            }
            else if(numready) {
            printf("There are %d sockets with activity!\n",numready);
            // check all sockets with SDLNet_SocketReady and handle the active ones.
            }
            

See Also

SdlNet Class | Tao.Sdl Namespace | SDLNet_SocketReady | SDLNet_AddSocket | SDLNet_DelSocket | SDLNet_AllocSocketSet | SdlNet.SDLNet_SocketSet | SdlNet.UDPsocket | SdlNet.TCPsocket