Not that easy to reproduce : doing a kill -9 on the server will properly close the connection, and the client will disconnect. The best solution to reproduce the scenario would be to have a remote server, connect the client, and pull the network cable from the server.
But in this case, there is nothing we can do : we have to wait for the underlying socket to timeout, and it all depends on your OS configuration.
The only way to 'detect' this use case is to combine the write with the idle status check. If you have done a write and the connection is idle for a moment (you decide how long is acceptable), then there is a problem.
To be clear : when you 'write' some data, it ends with some bytes being written in a system buffer, that will be read and written to the remote peer later. If teh OS can't write the data, it will retry many times, and it can take quite a while to be done (check the tcp_retries1 and tcp_retries2 parameter of your OS, but that may be up to 30 mins...).