Advertisement

winsock limited to 64 connections

Started by June 26, 2002 06:56 PM
8 comments, last by kindfluffysteve 22 years, 7 months ago
hello, I''m programming some kind of game for a uni project and in these forums i come across something about 64 connections are the maximun? can somebody clarify this? I am actually using some sort of wrapper class as I dont know how to use winsock directly. This number of 64 strikes me as being somewhat artificial - how do i get beyond it? I dont need to go beyond it, I''d just like to know how. the game im doing is a racing game. 64 is plenty but i have ideas for other things.
It''s a Windows quirk.

from winsock2.h/* * 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 WINSOCK2.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; 


Just put a #define FD_SETSIZE 1024 before #including winsock2.h

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
thanks, that should work fine.

and the same for winsock.h i think. looking at the source for the wrapper it uses winsock.h not winsock2.h

Should be the same for winsock.h yes.
Should be remembered though that FD_SETSIZE is a suggested upper limit, there is no guarantee that your program will actually be able to secure 1024 connection resources from the system...
Redefining FDSETSIZE "works" and will get you over 1000 connections. At least on a Win2K machine as I''ve done.

See my thread "1400 and then 900" for the issues I''ve had with redefining that variable.

Ben


IcarusIndie.com [ The Rabbit Hole | The Labyrinth | DevZone | Gang Wars | The Wall | Hosting ]
Still no guarantee So your program shouldn''t rely on absolutely being able to get that number of connections.
Advertisement
Oh, btw, the person who said it''s a windows quirk, i''m pretty damn sure that standard berkely sockets has a similar limit also, i''m not sure if it also uses FD_SETSIZE, but i am almost certain it has a limit (that can be redefined).

To the last AP, yep you''re correct - it''s a standard UNIX thing that stems from the fact that a socket is really just a type of file to the system. Linux defaults to 1024, as does solaris. Change FD_SETSIZE and it should work up to the limit imposed by system resources (i.e. based on memory availability, the size of the data type representing the socket descriptor, etc.)
I thought it was always 64/thread ?
www.persistentrealities.com for Inline ASM for VB, VB Fibre, and other nice code samples in C++, PHP, ASP, etc.<br/>Play Yet Another Laser Game!<br/>
64/thread? That''s not a sockets limitation. Maybe the style of asynchronous IO notification you are using or something (available Event handles maybe?).

I believe the only thing limiting available sockets in a straight socket app is system resources, and the FD_SETSIZE if you use select(). I frequently run 1000 connections in a single thread using select(), but my FD_SET is never larger than one (I select() sockets individually based on need to read/write).

This topic is closed to new replies.

Advertisement