简体   繁体   English

python中TCP连接的网络资源[Windows]

[英]Network resources for TCP connections in python [Windows]

Not sure if I have myself a problem with a python script I'm using. 不知道我是否对使用的python脚本有疑问。 Basically, it spawns threads, each creating a tcp connections. 基本上,它产生线程,每个线程都创建一个tcp连接。 Well the script finishes, i even check if any threads are still functioning, all of them return False ( not active which is good). 好了,脚本完成了,我什至还检查是否有任何线程仍在运行,它们全部返回False(不活动,这很好)。

The issue is that, if I check ( I use CurPorts from nirsoft ) some tcp connections ( between 1 and 9 sometimes ) are still in established status and sometimes in Sent status. 问题是,如果我检查(我使用nirsoft的CurPort),则某些tcp连接(有时在1到9之间)仍处于已建立状态,有时处于已发送状态。 Is that a problem ?They die out eventually, but after several minutes. 这是一个问题吗?他们最终死了,但几分钟后就消失了。 IS that on python's side fault, or basic windows procedure? 是在python的侧面错误还是基本的Windows过程?

I close the sockets with S.close, if that's of any help. 如果有帮助的话,我可以用S.close关闭套接字。 I'm not using daemon threads, just simple threads, and I just wait until all of them finish (t.join()) 我不是在使用守护程序线程,而只是简单的线程,我只是等到它们全部完成(t.join())

I need to know i I should worry or just let them be. 我需要知道我应该担心或随他们去吧。 reason is that they are eating up the ephemeral port number, and besides that i do not know if its keeping resources from me. 原因是他们正在吃掉临时端口号,而且我不知道它是否从我这里获取资源。

Would appreciate a noob friendly response. 希望菜鸟友好的回应。

Last Edit: I do use S.shutdown() before I send S.close() I do not do any error checking though, I have no idea how to go about doing that besides try: 上次编辑:在发送S.close()之前,我确实使用过S.shutdown(),但是我没有进行任何错误检查,除了尝试之外,我不知道该怎么做:

The simple answer is that TCP connections need to be gracefully shutdown before being closed. 简单的答案是,TCP连接需要在关闭之前正常关闭。

There are more details on how to call shutdown and close there: 有关如何调用shutdown并在此处关闭的更多详细信息:

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

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