for ( ;; )
{
fd_set readfds;
fd_set writefds;
FD_ZERO( &readfds );
FD_ZERO( &writefds );
FD_SET( sock, &readfds );
int maxfd = sock;
timeval to;
to.tv_sec = 2;
to.tv_usec = 0;
int n = select( maxfd + 1, &readfds, &writefds, NULL, &to );
if ( n > 0 )
{
if ( FD_ISSET( sock, &readfds ) )
{
int iread = recvfrom(sock, (char *)&usercount, sizeof(int), 0, (sockaddr *)&remote, &fromlen);
if(iread<=0)
{
throw Exception("Login error/n");
}
break;
}
}
else if ( n < 0 )
{
throw Exception("Login error/n");
}
sendto(sock, (const char*)&sendbuf, sizeof(sendbuf), 0, (const sockaddr*)&remote,sizeof(remote));
}