Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

kurifu

More Winsock problems.

This topic is 6016 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!