Assuming it is your own code, call setsockopt()
with option=SO_LINGER
and the linger
structure set to l_onoff=1
and l_linger=0
, and then close the socket. Any outbound data that is still buffered will be lost, which includes data already sent but not acknowledged.
Use this only for testing. It is insecure and unkind.
If it isn't your code in the server, write a client that does a GET of a large resource and closes the connection without reading any of the response.
Source: W.R. Stevens et al., Unix Network Programming, vol 1, 3rd edition, p.202.