都说用CSock有问题,大家最好还是直接用Api函数。

解决方案 »

  1.   


    我想这除了资源耗尽的硬件问题外,主要可能是系统的限制.
    不论是mfc类还是api都会遇到这个问题,就是windows限制了端口数.
    win95默认能开80个左右端口,但通过修改注册表可以取消这个限制.
    具体健值不记得了,不过我想应该就是这个问题.
      

  2.   

    在win2000下,我做过开5000个线程试过的,没有问题,传很短的数据。
      

  3.   

    to LJN(没有人) :谢谢你的建议,因为我是在做防火强的极限连接测试,所以我要建立尽量多的连接并保持这些连接,所以不必释放,而且我在机器重新启动后立即测试这样可以排除内存碎片的原因,但结果也是如此。
      

  4.   

    use winsock api, not use the silly mfc csocket
      

  5.   

    但是为什么用--mfc---不行呢? 难道一向被我们吹嘘的无所不能的--mfc---真的不行吗? 
      

  6.   

    我看资源耗尽的可能性比较大,csocket要处理消息,所以你子线程必须是有窗口的,占用了资源
      

  7.   

    How many simultaneous sockets can I have open with Winsock?
    On Win9x machines, there's a quite-low limit imposed by the kernel: 100 connections. You can increase this limit by editing the registry key HKLM\System\CurrentControlSet\Services\VxD\MSTCP\MaxConnections. On Windows 95, the key is a DWORD; on Windows 98, it's a string. I've seen some reports of instability when this value is increased to more than a few times its default value.The rest of this discussion will cover only Windows NT and Windows 2000. These systems have much higher intrinsic capabilities, and thus allow you to use many more sockets. But, the Winsock specification does not set a particular limit, so the only sure way to tell is to try it on all the Winsock stacks you plan on supporting.Beyond that vague advice, things get more complicated. The simplistic test is to just write a program that just opens sockets, to see where the program stops running: [C++ Example].The above program isn't terribly realistic. I've seen it grab more than 30,000 sockets before failing on Windows NT 4.0. Anecdotal evidence from the Winsock 2 mailing list puts the real limit much lower, typically 4,000 to 16,000 sockets, even on NT systems with hundreds of megabytes of physical memory. The difference is that the example program just grabs socket handles, but does not actually create connections with them or tie up any network stack buffers.According to people at Microsoft, the WinNT/Win2K kernel allocates sockets out of the non-paged memory pool. (That is, memory that cannot be swapped to the page file by the virtual memory subsystem.) The size of this pool is necessarily fixed, and is dependent on the amount of physical memory in the system.On Intel x86 machines, the non-paged memory pool stops growing at 1/8 the size of physical RAM, with a hard maximum of 128 megabytes. The hard limit is 256 megabytes on Windows 2000. Thus for NT 4, the size of the non-paged pool stops increasing once the machine has 1 GB of RAM. On Win2K, you hit the wall at 2 GB.The amount of data associated with each socket varies depending on how that socket's used, but the minimum size is around 2 KB. Overlapped I/O buffers also eat into the non-paged pool, in blocks of 4 KB. (4 KB is the x86's memory management unit's page size.) Thus a simplistic application that's regularly sending and receiving on a socket will tie up at least 10 KB of non-pageable memory.Assuming that simple case of 10 KB of data per connection, the theoretical maximum number of sockets on NT 4.0 is about 12,800s, and on Win2K 25,600.I have seen reports of a 64 MB Windows NT 4.0 machine hitting the wall at 1,500 connections, a 128 MB machine at around 4,000 connections, and a 192 MB machine maxing out at 4,700 connections. It would appear that on these machines, each connection is using between 4 KB and 6 KB. The discrepancy between these numbers and the 10 KB number above is probably due to the fact that in these servers, not all connections were sending and receiving all the time. The idle connections will only be using about 2 KB each.So, adjusting our "average" size down to 6 KB per socket, NT 4.0 could handle about 21,800 sockets and Win2K about 43,700 sockets. The largest value I've seen reported is 16,000 sockets on Windows NT 4.0.There's one more complication to keep in mind: your server program will not be the only thing running on the machine. If nothing else, there will be core OS services running. These other programs will be competing with yours for space in the non-paged memory pool.
      

  8.   

    to:LJN(没有人)
    >win95默认能开80个左右端口,但通过修改注册表可以取消这个限制.
    我用的是98系统,默认的是90个左右,修改注册表可以取消这个限制(以前解决过,但每人记得如何改).
    请你也帮忙问问,解决了我给你500分!(是在很急,客户已经投诉半个多月了,我的程序必须在98下跑,只有改注册表一途了。连接数要达到150)。
    谢谢!!!
      

  9.   

    to:masterz() 
    请问你的win98是什么版本的?
    运行regedit,找不到HKLM\System\CurrentControlSet\Services\VxD\MSTCP\MaxConnections,
    只有HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP在MSTCP\下只有[+]Ndi、[+]Parameters、ServiceProvider,找遍了下面的子键等等都找不到MaxConnections。
    请大侠帮忙,搞定给500分!!!
      

  10.   

    是不是自己创建一个就行了?
    另:HKLM ==HKEY_LOCAL_MACHINE?
      

  11.   

    已经搞定!
    LJN(没有人)、masterz()两人都有分(各250分)!
    请两人前去领分。