Connecting Tech Pros Worldwide Forums | Help | Site Map

Select() UDP and TCP

Member
 
Join Date: Mar 2007
Posts: 47
#1: Nov 9 '08
hi. ok my problem is that i have been using TCP for a while and now i want to change to UDP. Im using the select I/0 method.

i have a listening thread like this :
Expand|Select|Wrap|Line Numbers
  1. void Server::vListeningThread( LPVOID pParam )
  2. {
  3.     Server *pServer = (Server*)pParam;
  4.     SOCKET socketClient;
  5.     do
  6.     {
  7.         socketClient = accept( *pServer->p_socketServer, 0, 0 );
  8.  
  9.         if ( socketClient == SOCKET_ERROR || pServer->usNumberOfClients >= pServer->usMAX_CLIENTS ) 
  10.         {
  11.             // send an error code to client //////////////////////////////////////
  12.             closesocket( socketClient );
  13.         }
  14.         else 
  15.         {
  16.             WaitForSingleObject( pServer->handleMutex, INFINITE );
  17.             FD_SET( socketClient, &pServer->fdsetMaster );
  18.             ReleaseMutex( pServer->handleMutex );
  19.             pServer->usNumberOfClients++;
  20.         }
  21.  
  22.     }while( pServer->bConnected );
  23.  
  24. }
now im unsure how to change it into UDP.

does the new socket of data that has been sent go straight into the FD_SET? Therefore when im polling through the set i would have to check if it has been set or not?

Please help, im a little bit confused with this?

thanks

sicarie's Avatar
Moderator
 
Join Date: Nov 2006
Location: USA
Posts: 3,929
#2: Nov 9 '08

re: Select() UDP and TCP


This looks like C/C++ code, am I right?

If so, I will move this over to the C/C++ Forum.
Member
 
Join Date: Mar 2007
Posts: 47
#3: Nov 9 '08

re: Select() UDP and TCP


well yeah, im using WinSock, thought it would more suitable for the network forums. Ok please move it to the c++ forums
Member
 
Join Date: Mar 2007
Posts: 47
#4: Nov 9 '08

re: Select() UDP and TCP


actually ill just create a new one on c++ forums. this can be deleted
Reply