Throw IOException when writing closed socket.

@marco-c I found, why need this temp fix (3d3364154ad6e430bf823ebece03be4a52218092);