0

I've often found myself wanting to test various nonblocking socket code, but I'm unsure how to simulate (or otherwise intentionally cause) an event to test nonblocking reads/writes and the various buffers in play - in other words, to cause a 'blocking event' on a given socket.

How would this be done? I imagine that this would require low level control over the TCP session in order to intentionally cause an EWOULDBLOCK error on the receiving socket

JSON
  • 1,819
  • 20
  • 27
  • Take a look at [TestSocket](http://sockettest.sourceforge.net/), or [this](http://stackoverflow.com/questions/515328/good-tool-for-testing-socket-connections) thread which lists various test frameworks. – Jens Jun 06 '15 at 12:14
  • Your suggestions seem to just send commands to simulate a normal server or client. A test client in my case would have to pause the TCP session to simulate an excessive delay in the transmission. In other words, it would have to delay sending the end of a packet or frame, or delay the ACK (without causing retransmission) , preventing the remote endpoint from receiving what it sees as a whole transmission and returning without error. – JSON Jun 06 '15 at 13:39

1 Answers1

0

If you have a set of exact scenario you wish to check you program against, you can use ScaPy to send arbitrary packets with desired delays. It is possible to start from a captured session in *.pcap format, so that you won't have to handcraft all the packets, just modify/add/delay some, maybe generate a testing script, etc. See Sending packets from pcap with changed src/dst in scapy. TCPReplay can also replay *.pcap file with desired speed (packets/sec).

If you want to test your program in harsh network environment (e. g. simulate packet loss and retransmission), there are readily available tools for this, e. g. for Linux take a look at Simulate delayed and dropped packets on Linux (and links to Windows tools from there).

Community
  • 1
  • 1
PlushBeaver
  • 346
  • 1
  • 9