See if a socket has activity
non-zero for activity. zero is returned for no activity.
Binds to C-function call in SDL_net.h:
#define SDLNet_SocketReady(sock) ((sock != NULL) && ((SDLNet_GenericSocket)sock)->ready)
// 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. } } }
SdlNet Class | Tao.Sdl Namespace | SDLNet_CheckSockets | SDLNet_AddSocket | SDLNet_DelSocket | SDLNet_AllocSocketSet | SdlNet.SDLNet_SocketSet | SdlNet.UDPsocket | SdlNet.TCPsocket