<p>I have a network C++ program in Windows that I'd like to test for network disconnects at various times.  What are my options?</p>

<p>Currently I am:</p>

<ol>
<li>Actually disconnecting the network wire from the back of my computer</li>
<li>using ipconfig /release</li>
<li>Using the <a href="http://www.nirsoft.net/utils/cports.html" rel="nofollow noreferrer">cports</a> program to close out the socket completely</li>
</ol>

<p>None of these methods though are ideal for me, and I'd like to emulate network problems more easily. </p>

<p>I would like for sometimes connects to fail, sometimes socket reads to fail, and sometimes socket writes to fail.  It would be great if there was some utility I could use to emulate these types of problems.</p>

<p>It would also be nice to be able to build some automated unit tests while this emulated bad network is up.</p>

[{'answer_id': 61530, 'author': 'Gulzar Nazim', 'author_id': 4337, 'author_profile': 'https://Stackoverflow.com/users/4337', 'pm_score': 2, 'selected': False, 'text': '<p>The closest I can think of is doing something similar with <a href="http://www.shunra.com/vedesktop.aspx" rel="nofollow noreferrer">VEDekstop</a> from Shunra..</p>\n\n<p><a href="http://sqlblog.com/blogs/john_paul_cook/archive/2008/04/13/simulating-high-latency-and-low-bandwidth-for-database-connectivity-testing.aspx" rel="nofollow noreferrer">Simulating High Latency and Low Bandwidth in Testing of Database Applications</a> </p>\n\n<p><em>Shunra VE Desktop Standard is a Windows-based client software solution that simulates a wide area network link so that you can test applications under a variety of current and potential network conditions – directly from your desktop.</em> </p>\n'}, {'answer_id': 61603, 'author': 'Douglas Leeder', 'author_id': 3978, 'author_profile': 'https://Stackoverflow.com/users/3978', 'pm_score': 5, 'selected': True, 'text': '<p>You might want to abstract the network layer, and then you can have unit tests that inject interesting failure events at appropriate points.</p>\n'}, {'answer_id': 61776, 'author': 'McKenzieG1', 'author_id': 3776, 'author_profile': 'https://Stackoverflow.com/users/3776', 'pm_score': 0, 'selected': False, 'text': '<p>You can subclass whatever library class you are using to manage your sockets (presumably CAsyncSocket or CSocket if you are using MFC), override the methods whose failure you want to test, and insert appropriate test code in your overrides.</p>\n'}, {'answer_id': 13007378, 'author': 'Flint LIU', 'author_id': 1764637, 'author_profile': 'https://Stackoverflow.com/users/1764637', 'pm_score': 0, 'selected': False, 'text': '<p>There are some methods you can use, it is depend on which level you want to test. For function level, you can use XUNIT testing framework to mock a responce. For software level, you can use a local proxy server to contral connection.</p>\n'}]
['https://Stackoverflow.com/questions/61524', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3153/']