Simulate reset / timeout socket connections on Windows 7

I would like to simulate a socket connection bad to test my application. The goal is to check if my Java code is behaving as it expected when a long socket connection on the remote server gets reset at runtime or on the server becomes unavailable.

I tried to create a firewall rule in a Windows firewall. However, enabling this rule does not seem to affect an already open socket connection. Pulling a network cable is not an option, because I have to run these tests through connecting the remote desktop to the server that is running my code.

+4
source share
4 answers

I understand that this is not directly under Windows, but given the nature of Java, it can still work.

On Linux, there is a program called Netem, which, given that your java code, may work. I have never used it, so I can’t confirm its capabilities or use it, but there are usage examples here . You can quite trivially run Linux inside a virtual machine (for example, free (both in beer and in the form of free speech that you enjoy in the UK) VirtualBox) and, hopefully, your Java application inside that.

It may not be perfect and regret the general lack of know-how, but it can work for what you need

+1
source

A simple, ugly and dangerous way to do this is to quickly disable and then enable the right NetworkAdapter through VBScript and WMI.

Using a WAN emulator to simulate packet loss, disconnection, and high latency will be a more reliable, but even harder to configure solution. Your best free option here is dummynet , although there are many expensive, user-friendly solutions out there.

If there is an easy way to do this on Windows and Linux without having to boot boot disks and FreeBSD virtual servers with two network cards, I would also like to hear that!

0
source

You can just kill the client application.

In addition, you can do this by creating a very simple proxy application for this, which usually just sends data, but which you can program to give it commands to perform other actions. Or, instead of programmatically simulating a dropped connection, just run this proxy application if for some reason you cannot kill your client application.

0
source

Set the socket read timeout programmatically to 1 millisecond and you will always get java.net.SocketTimeoutException.

0
source

All Articles