gpt4 book ai didi

Python socket.close() 在脚本退出之前不起作用

转载 作者:行者123 更新时间:2023-11-30 23:23:57 24 4
gpt4 key购买 nike

客户端代码:

fwd = socket.socket(socket.AF_INET,socket.SOCK_STREAM)    
fwd.connect((oriIp,oriPort)
fwd.close()

我发现 close() 函数不起作用。我的服务器(c#)显示连接仍然​​有效。直到python脚本关闭,服务器才会显示连接已关闭的状态。

我使用 IronPython 2.7。

最佳答案

请参阅套接字的 python 文档:

Note: close() releases the resource associated with a connection but does not necessarily close the connection immediately. If you want to close the connection in a timely fashion, call shutdown() before close().

https://docs.python.org/2/library/socket.html

关于Python socket.close() 在脚本退出之前不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23733719/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com