views:

1701

answers:

5

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?

A: 

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.

John Saunders
A: 

Why not just unplug the network cable?

JonnyBoats
+1  A: 

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. 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.

D.Shawley
A: 

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

Assaf Lavie
A: 

Why not use a firewall? you can either block specific ports or processes. The built-in Windows firewall has an API, so you can create a tool that will connect and disconnect your app in whatever way you want.

eran
That will prevent new connections from being created; I believe jonathanrice42 is asking about already existing connections.
Piskvor