🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

More Winsock problems.

Started by
3 comments, last by kurifu 22 years, 6 months ago
Ok, I tried reading the article on GameDev entitled, How to create a Non blocking server, and I end up with an overflow problem in the function that accepts connections: (posted)

HRESULT clTServerSocketControl::CheckConnections( ){
        int             nSelect;
        int             nfds;
        fd_set          fdConn;
        int             nClient_Length;

        timeout.tv_sec  = 0;
        timeout.tv_usec = 0;

// FIRST, CAN WE HANDLE MORE CONNECTION?
        if( ClientsConnected >= MAX_CONNECTS ){
                Log( "WARNING: Max clients reached" );
                return -1;
        }

// LETS CHECK FOR MORE PEOPLE TRYING TO CONNECT TO OUR SERVER...
        FD_ZERO( &fdConn );
        FD_SET( ListeningSocket, &fdConn ); // GET DATA FROM LISTENING SOCKET

        nfds = ListeningSocket + 1; // TWO CLIENTS SHOULD NEVER HAVE THE SAME nfds VALUE
        nSelect = select( nfds, &fdConn, NULL, NULL, &timeout ); // CHECK FOR INCOMING DATA

// HANDEL INCOMING CONNECTION REQUESTS
        if( nSelect > 0 ){ // SOMEONE IS TRYING TO CONNECT
                for( int index = 0; index < MAX_CONNECTS; index ++ ){
                        if( Clients[ index ].InUse == NO ){
                        // HERE WE ACCEPT THE INCOMING CONNECTION
                                Clients[ index ].ClientSocket = accept( ListeningSocket,
                                        (struct sockaddr *)&Clients[ index ].ClientSocket,
                                        &nClient_Length );

                        // THE CLIENT IS NOW CONNECTED
                                ClientsConnected++;
                                //char    *ClientIP = inet_ntoa( Clients[ index ].clnt_addr.sin_addr );
                                Log( "CONNECT: Connection Accepted" );

                        // FLAG THE SOCKET
                                Clients[ index ].InUse = YES;
                                Clients[ index ].PacketID = 0;

                        // WE FOUND A SEAT FOR THE CLIENT, LETS STOP SEARCHING
                                break;
                        }
                }
        }

        return S_OK;
}
 
What happens is that when one client tries to connect, it seems to be reading the client over and over and over again, and keep accepting its connection, well attempting to anyway, even though the client has already been connected. The problem, as far as I can tell, is in the select( ) function. But still this leads me to ask, what is wrong with it? Gamedev''s AI Auto-Reply bot.
Gamedev's AI Auto-Reply bot.
Advertisement
Not sure if this would cause the problem, but check your accept() call. You are passing the socket to the sockaddr parameter. This is bound to be troublesome. Fix that and see what happens.

It looks like you already have a member in the Client structure (see the inet_ntoa line that is commented out).


-Brannon
-Brannon
Actually I caught that error yesterday before I went off to my other job in life... and I thought it to would fix it. I did not get the chance until now to even attempt to fic that error, however the problem still stands that my computer is trying to constantly re-accept the connection.

As of late, I have no idea why it is doing this.
Gamedev's AI Auto-Reply bot.
I assume that you have set non-blocking mode on your listening socket. Do the clients actually get connected? Are you checking to make sure that accept() isn''t returning SOCKET_ERROR (on Win32)? To be anal, I would also check to make sure the listening socket was set in the fd_set struct (using FD_ISSET()). Something like:

  if (nSelect > 0 && FD_ISSET(ListeningSocket, &fdConn)){   ...}  


Is this by any chance multi-threaded?

-Brannon
-Brannon
why not use asynchrnous sockets?
or r u alreay?
im still a novice at this but ive never had to call some of these functions

This topic is closed to new replies.

Advertisement