Thread: Windows TCP Server Can't Handle >100 Clients

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    Okay, sorry to bump this thread, but just in case people run into the same problem I do with this, Overlapped I/O has *absolutely nothing* to do with what was going wrong.

    See winsock.h:
    Code:
    typedef UINT_PTR        SOCKET;
    
    /*
     * Select uses arrays of SOCKETs.  These macros manipulate such
     * arrays.  FD_SETSIZE may be defined by the user before including
     * this file, but the default here should be >= 64.
     *
     * CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
     * INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.
     */
    #ifndef FD_SETSIZE
    #define FD_SETSIZE      64
    #endif /* FD_SETSIZE */
    
    typedef struct fd_set {
            u_int   fd_count;               /* how many are SET? */
            SOCKET  fd_array[FD_SETSIZE];   /* an array of SOCKETs */
    } fd_set;
    And there you go. I had this problem years ago with my servers like this and I simply forgot this one, simple, stupid rule--FD_SETSIZE limits the amount of file descriptors you can use on any server. This has nothing to do with the I/O, it's simply because the number of file descriptors was capped to 64 by default by winsock.h. All you have to do is #define FD_SETSIZE to a multiple of 1024 and you're all set. I can't believe I missed this.

  2. #2
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Thread per connection runs into problems with more than about 16 connections, as you are finding out. Use a connection pool.

  3. #3
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    Quote Originally Posted by abachler View Post
    Thread per connection runs into problems with more than about 16 connections, as you are finding out. Use a connection pool.
    What does "thread per connection" have to do with anything? I'm not creating a new thread for every connection, you really need to take a look at the code. I'm able to handle up to 65535 connections now, tested it over a few machines and gotten into the tens of thousands, which is more than I need.
    Last edited by Xterria; 11-02-2009 at 02:42 AM.

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Perhaps you could point out the parts of your code you are having issues with, or do you expect me to read through the 90% that are irrelevant to the problem?

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Quote Originally Posted by abachler View Post
    Perhaps you could point out the parts of your code you are having issues with, or do you expect me to read through the 90% that are irrelevant to the problem?
    What problem? He posted to say that he fixed the problem he was having, and gave the solution in case others came across this thread down the road.
    bit∙hub [bit-huhb] n. A source and destination for information.

  6. #6
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    What problem? He posted to say that he fixed the problem he was having, and gave the solution in case others came across this thread down the road.
    Exactly. abachler, you seriously need to read through the thread before replying. I'm seeing you post prematurely all over this board.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Where's the EPIPE signal?
    By marc.andrysco in forum Networking/Device Communication
    Replies: 0
    Last Post: 12-23-2006, 08:04 PM
  2. Server with multiple clients
    By Thantos in forum Networking/Device Communication
    Replies: 20
    Last Post: 09-02-2003, 05:52 PM
  3. a simple C question...
    By DramaKing in forum C Programming
    Replies: 10
    Last Post: 07-28-2002, 02:04 PM
  4. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 01:54 PM
  5. g_hWndMain = hWnd;error C2065,C2440
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 12-09-2001, 03:36 PM