简体   繁体   English

在Windows中切断/终止tcp连接

[英]sever/kill tcp connection in windows

I would like to see how a program responds when it's connection is severed. 我希望看到一个程序在断开连接时如何响应。 Aside from disabling the network card, is there a way to sever a tcp connection in Windows without killing the process, or the thread that owns the connections? 除了禁用网卡之外,有没有办法在Windows中切断tcp连接而不会终止进程,或者拥有连接的线程?

The closest thing that I've found to generating an OS error is to use something like TcpView to look at what sockets are open and sever them. 我发现生成操作系统错误的最接近的事情是使用类似TcpView的东西来查看哪些套接字是打开的并切断它们。 I'm not sure exactly what it does to sever the connection, but it does close it in a way that an application can see. 我不确定它是如何切断连接的,但它确实以应用程序可以看到的方式关闭它。

通过SysInternals的 TCPView可以关闭连接(并查看所有打开的连接)。

One thing I've seen done is to have the network code written in such a way that a connection can be severed remotely. 我所看到的一件事就是让网络代码以一种可以远程切断连接的方式编写。 A product I once worked on was written that way. 我曾经做过的产品是这样编写的。 We even had a set of torture tests that would randomly break the connections. 我们甚至进行了一系列酷刑测试,这些测试会随机打破连接。 The product was meant to be transactional, and it was instructive to see how it behaved. 该产品本来是交易性的,看看它的表现是有益的。

Of course, we then found a customer whose network was actually breaking connections all the time, and were very glad we'd tested so hard. 当然,然后我们找到了一个客户的网络实际上一直在断开连接,并且非常高兴我们进行了如此努力的测试。

为什么不拔掉网线?

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

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