简体   繁体   English

Windows套接字

[英]Windows sockets

Does windows closes idle sockets? Windows是否会关闭空闲的套接字? I mean if I'm a client connecting to a service on Windows server, is it possible that Windows server closes the connection after certain idle-time? 我的意思是,如果我是连接到Windows服务器上的服务的客户端,则Windows服务器是否有可能在特定的空闲时间后关闭连接?

If yes, how to change this behaviour, or at least change the idle-time value? 如果是,如何更改此行为,或者至少更改空闲时间值?

Thanks in advance. 提前致谢。

The behavior depends on the SO_KEEPALIVE socket option. 该行为取决于SO_KEEPALIVE套接字选项。 Here's the MSDN page about it. 这是关于它的MSDN页面。 After some further digging you can adjust the KEEPALIVE semantics with a WSAIoctl and the SIO_KEEPALIVE_VALS Control Code . 经过进一步的挖掘后,您可以使用WSAIoctl和SIO_KEEPALIVE_VALS控制代码来调整KEEPALIVE语义。

I find, that if you control both ends, it is usually better to implement keepalive messages as part of the protocol used to communicate between the client and server instead of relying on SO_KEEPALIVE. 我发现,如果您控制两端,通常最好将Keepalive消息作为用于客户端和服务器之间通信的协议的一部分来实现,而不要依赖SO_KEEPALIVE。

I would imagine that depends on the protocol, implementation and perhaps server config. 我想这取决于协议,实现以及服务器配置。

PuTTY has an option to prevent timing out of SSH sessions by periodically sending null packets to the server - I suspect this is a simply packet with no actual payload. PuTTY可以选择通过定期向服务器发送空数据包来防止SSH会话超时-我怀疑这是一个没有实际有效负载的简单数据包。 Perhaps you could implement something like this? 也许您可以实现这样的事情?

On MSDN you will find that the defaul keep-alive timeout is set to 2 hours. MSDN上,您会发现默认的keep-alive超时设置为2小时。 You are maybe able to manipulate this by using setsockopt/SO_SNDTIMEO/getsockopt 您也许可以通过使用setsockopt / SO_SNDTIMEO / getsockopt来操纵它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM