ren*_*ish 3 c sockets networking timeout tcp
我做了一个实验:
服务器侦听端口8804接受客户端的连接,然后无限地向客户端发送数据.我关闭了网络.
所以:
1.为什么在系统上阻塞的服务器调用"write"会抛出"Connection timeout"错误.为什么不是客户?
2.如何让客户端找到连接实际上是关闭的.
3.当网络不起作用时,为什么服务器和客户端的状态都"已建立"?
感谢您的回答 !
s):# Do this before you accept() anything on the socket
s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
Run Code Online (Sandbox Code Playgroud)
编辑:
因为您正在使用C,所以指向Linux TCP Keepalive Howto的链接
注意
1. RFC 1122:第4.2.3.5节"TCP连接失败"
2. RFC 1122:第4.2.3.6节"TCP Keepalive"