@Test ( timeout = 2000 )
    public void serverWriteToSocketClosedByClient () throws Exception {
        Socket[] sockets = connectToServer();
        try ( Socket serverSocket = sockets[ 0 ];
              Socket clientSocket = sockets[ 1 ] ) {

            clientSocket.close();
            // wait for close to propagate
            Thread.sleep(100);

            IOException exception = null;
            try {
                /*
                 * http://www.unixguide.net/network/socketfaq/2.1.shtml
                 * http://www.faqs.org/rfcs/rfc793.html
                 * 
                 * The TCP RFC allows the open side to continue sending data. In
                 * most (all?) implementations, the closed side will respond with a
                 * RST. For this reason, it takes two writes to cause an IOException
                 * with TCP sockets. (or more, if there is latency)
                 * 
                 * However, it is expected that the write give an IOException as
                 * soon as possible - which means it is OK for our socket
                 * implementation to give an IOException on the first write.
                 */
                serverSocket.getOutputStream().write(new byte[] {
                    '1'
                });
                Thread.sleep(100);
                serverSocket.getOutputStream().write(new byte[] {
                    '2'
                });
            }
            catch ( IOException e ) {
                exception = e;
            }

            assertNotNull("Server should see an IOException when writing to a socket that the client closed.", exception);

        }
    }