在 Windows 中切断/终止 tcp 连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/824818/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:24:04  来源:igfitidea点击:

sever/kill tcp connection in windows

windowstcpconnectionkill

提问by Aldur

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 连接?

采纳答案by D.Shawley

The closest thing that I've found to generating an OS error is to use something like TcpViewto look at what sockets are open and sever them. 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.

我发现产生操作系统错误的最接近的事情是使用类似TcpView 的东西来查看哪些套接字是打开的并切断它们。我不确定它究竟是做什么来切断连接的,但它确实以应用程序可以看到的方式关闭它。

回答by Assaf Lavie

TCPView by SysInternalslets you close a connection (and see all open connections).

套装软件的Sysinternals的,您可以关闭连接(并查看所有打开的连接)。

回答by John Saunders

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.

当然,我们随后发现了一位客户的网络实际上一直在断开连接,并且很高兴我们进行了如此努力的测试。

回答by JonnyBoats

Why not just unplug the network cable?

为什么不拔掉网线?