Maximum Number of Sockets an Application Can Use


The maximum number of sockets supported by a particular Windows Sockets supplier is implementation-specific. An application should make no assumptions about the availability of a certain number of sockets.

More Information

Details of the Windows Sockets implementation are described in the WSAData structure returned by WSAStartup() and defined as follows:
struct WSAData {
WORD wVersion;
WORD wHighVersion;
char szDescription[WSADESCRIPTION_LEN+1];
char szSystemStatus[WSASYSSTATUS_LEN+1];
unsigned short iMaxSockets;
unsigned short iMaxUdpDg;
char FAR * lpVendorInfo
On return from WSAStart() on Windows NT

   iMaxSockets = 0x7fff (32767)
where iMaxSockets is the maximum number of sockets that a single process can potentially open. A Windows Sockets implementation can provide a global pool of sockets for allocation to any process, or it can allocate per-process resources for sockets. The number can reflect the way in which the Windows Sockets DLL or the networking software was configured. The number can also be used when writing an application as an indication of whether the Windows Sockets implementation can be used by the application.

For example, an X Windows server might check iMaxSockets when it starts. If the number of sockets is less than 8, the application displays an error message instructing the user to reconfigure the networking software. (This is a situation in which the szSystemStatus text might be used.) There is no guarantee that a particular application can actually allocate iMaxSockets sockets, because there may be other Windows Sockets applications in use.

However, independent of the number of sockets supported by a particular implementation is the issue of the maximum number of sockets that an application can actually use.

The maximum number of sockets that a Windows Sockets application can use is determined at compile time by the manifest constant FD_SETSIZE. To do this, from the Win32 SDK WINSOCK.H file:

* 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.
#ifndef FD_SETSIZE
#define FD_SETSIZE 64
#endif /* FD_SETSIZE */
This value is used in constructing the fd_set structures used in select(). The default value in WINSOCK.H is 64. If an application is designed to be capable of working with more than 64 sockets, define the manifest FD_SETSIZE in every source file before including WINSOCK.H. One way of doing this is to include the definition within the compiler options in the makefile, such as adding -DFD_SETSIZE=128 as an option to the compiler command line for Microsoft C.

NOTE: Defining FD_SETSIZE as a particular value has no effect on the actual number of sockets provided by a Windows Sockets implementation.

رقم الموضوع: 111855 - آخر مراجعة: 31‏/10‏/2006 - المراجعة: 1