Thread: Allowing 1 too many clients

  1. #1
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    404

    Allowing 1 too many clients

    I am writing a server and I am probably blind to what I have done wrong. I want to limit the amount of connections to 10, but it is currently allowing 11. Not that this is a big deal, but I am confuzzled.

    csck[0 - 9] are all initialized to INVALID_SOCKET
    After I get the message "All sockets full ...", it allows one more connection, which doesn't result in any more messages to the console. After the 11th, any clients that try to connect get forcefully rejected, as desired.

    I am designing on 32-bit Windows 7 Beta.

    lsck is the listening socket, csck[] are the specific client sockets

    Code:
    	while (lsck != INVALID_SOCKET)
    	{
    		if (full == 1)
    		{
    			printf("All sockets full, waiting 60 seconds for one or more to free up\n");
    			Sleep(60000);
    		}
    
    		for (i = 0; i < 10; i++)
    		{
    			if (csck[i] == INVALID_SOCKET)
    			{
    				printf("\tListening on socket %d\n", i);
    				csck[i] = accept(lsck, NULL, NULL);
    				if (csck[i] == INVALID_SOCKET)
    				{
    					closesocket(lsck);
    					printf("Error on Listening Socket ... Closing down\n");
    					break;
    				}
    				else
    				{
    					printf("\tClient connected\n");
    					/*
    						Make child threads and stuff
    					*/
    					break;
    				}
    			}
    
    			full = (i == 9) ? 1 : 0;
    		}
    	}
    Edit: The sockets will be freed from inside the thread when the connection is terminated, but I haven't designed that part yet.
    Last edited by carrotcake1029; 03-01-2009 at 02:31 PM.

  2. #2
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    Well, I don't know me neither.

    Guess you should try with a debugger. And personally, I find it a bit weird to develop on Windows 7, but that's just a personal opinion, have nothing against it.
    I hate real numbers.

  3. #3
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    404
    Ya, probably not the best system to develop on atm, but unless they changed some very very basic instructions, I don't see what could go wrong.

    I'm not going to worry about it. At least it doesn't inhibit the development of the rest of my progress.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Communicating clients that are connected to the same server
    By seforix in forum Networking/Device Communication
    Replies: 6
    Last Post: 05-29-2009, 08:13 PM
  2. Multiple clients to "internet" server
    By Zarniwoop in forum C Programming
    Replies: 2
    Last Post: 10-11-2008, 11:04 PM
  3. Socket Help - Multiple Clients
    By project95talon in forum C Programming
    Replies: 5
    Last Post: 11-17-2005, 02:51 AM
  4. Server - All Clients Send.
    By mill1k in forum Networking/Device Communication
    Replies: 13
    Last Post: 09-30-2004, 12:23 PM
  5. Replies: 2
    Last Post: 03-05-2002, 05:52 AM