SO_LINGER和关闭套接字(Winsock) [英] SO_LINGER and closing sockets(WINSOCK)

查看:181
本文介绍了SO_LINGER和关闭套接字(Winsock)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哎。
我写一个多线程Winsock应用程序,并具有关闭插座的一些问题IM。
首先,是有一些同时打开插座是否有限制?让说像32路都在一次。

hey. im writing a multithreaded winsock application and im having some issues with closing the sockets. first of all, is there a limit for a number of simultaneously open sockets? lets say like 32 sockets all in once.

我建立的插座中的一个连接,并传递信息,并一切正常。
问题是,当我拔下插座,然后重新连接到相同的目的地,我从服务器获取一个RST SYN我后。
我没有在code服务器应用程序,所以我不能调试。

i establish a connection on one of the sockets, and passing information and it all goes right. problem is when i disconnect the socket and then reconnect to the same destination, i get a RST from the server after my SYN. i dont have the code for the server app so i cant debug it.

当我用SO_LINGER并在每届会议结束时发送一个RST标志 - 它的工作。
但我不想结束我的连接这种方式。
不使用时,SO_LINGER一个FIN标志被送往但似乎连接没有真正结束。

when i used SO_LINGER and it sent a RST flag at the end of each session - it worked. but i dont want to end my connections this way. when not using SO_LINGER a FIN flag was sent but it seems the connection was not really closed.

任何帮助吗?
谢谢

any help? thanks

推荐答案

首先,我同意尼古拉,你结合你的客户端套接字?

Firstly, I agree with Nikolai, are you binding your client socket?

如果这样,它听起来就像在服务器端插座仍处于 TIME_WAIT 并丢弃新的连接尝试。通过结合你强制服务器尝试和重复使用,目前在2 MSL等待期间完全相同的连接的客户端接口,它不能在这个时间点,重复使用,所以你所看到的,你看到的。有通常不需要绑定客户端端口,停止这样做,你的问题可能会消失。

If so it sounds like the socket on the server side is still in TIME_WAIT and is discarding the new connection attempt. By binding the client socket you're forcing the server to try and reuse the exact same connection that is currently in the 2MSL wait period, it can't be reused at this point in time and so you're seeing what you're seeing. There's usually no need to bind the client port, stop doing it and your problem will likely go away.

其次,是的,有限制的开放式插槽在Windows平台上的数量,但是他们是资源相关的,而不是一些硬codeD编号。

Secondly, yes, there are limits to the number of open sockets on Windows platforms but they're resource related rather than some hard coded number.

每个打开的套接字使用了一些非分页池的内存和每个挂起读取或写入套接字的要求也很可能在I / O使用这两种非分页池,并有记忆锁定在内存页(有一个限制可锁定的页数)。这在Vista上说,后来有更多的非分页池比早期版本的Windows,即使这样我已经成功地实现在pretty低规格的XP盒(见这里超过70,000个并发活动连接可供选择: http://www.lenholgate.com/blog/2005 /11/windows-tcpip-server-performance.html )。请注意,有一些对你可以建立(这是更可能是你的兴趣)的出站连接数的几个独立的限制,但在默认情况下是4000左右,可以通过设置 MAX_USER_PORT 在这里看到:<一href=\"http://stackoverflow.com/questions/1536550/maximum-number-of-concurrent-tcp-ip-connections-win-xp-sp3/1537561#1537561\">Maximum并发的TCP / IP连接数 - Win XP的SP3 了解更多详情。

Each open socket uses some 'non paged pool' memory and each pending read or write request on a socket is also likely to use both 'non paged pool' and have pages of memory locked in memory during I/O (there's a limit to the number of pages that can be locked). That said on Vista and later there's much more 'non paged pool' available than on earlier versions of Windows and even then I've managed to achieve more than 70,000 concurrent active connections on a pretty low spec XP box (see here: http://www.lenholgate.com/blog/2005/11/windows-tcpip-server-performance.html). Note that there are some separate limits on the number of outbound connections that you can establish (which is more likely to be of interest to you) but that's around 4000 by default and can be tuned by setting MAX_USER_PORT see here: Maximum number of concurrent TCP/IP connections - Win XP SP3 for more details.

这篇关于SO_LINGER和关闭套接字(Winsock)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆