Tao.Sdl SDK Documentation

SdlNet.SDLNet_SocketReady Method 

See if a socket has activity

[Visual Basic]
Public Shared Function SDLNet_SocketReady( _
   ByVal sock As IntPtr _
) As Integer
[C#]
public static int SDLNet_SocketReady(
   IntPtr sock
);

Parameters

sock
The socket to check for activity. Both UDPsocket and TCPsocket can be used with this function.

Return Value

non-zero for activity. zero is returned for no activity.

Remarks

Check whether a socket has been marked as active. This function should only be used on a socket in a socket set, and that set has to have had SDLNet_CheckSockets (see SDLNet_CheckSockets) called upon it.

Binds to C-function call in SDL_net.h:

            #define SDLNet_SocketReady(sock) ((sock != NULL) && ((SDLNet_GenericSocket)sock)->ready)
            

Example

            // Wait forever for a connection attempt
            //SDLNet_SocketSet set;
            //TCPsocket serversock, client;
            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.
            if(SDLNet_SocketReady(serversock)) {
            client=SDLNet_TCP_Accept(serversock);
            if(client) {
            // play with the client.
            }
            }
            }
            
To just quickly do network handling with no waiting, we do this.
            // Check for, and handle UDP data
            //SDLNet_SocketSet set;
            //UDPsocket udpsock;
            //UDPpacket *packet;
            int numready, numpkts;
            numready=SDLNet_CheckSockets(set, 0);
            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.
            if(SDLNet_SocketReady(udpsock)) {
            numpkts=SDLNet_UDP_Recv(udpsock,&packet);
            if(numpkts) {
            // process the packet.
            }
            }
            }
            

See Also

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