Don't attempt to write if the connection is closed.
Merge pull request #371 from trestletech/no-write-closed

Don't attempt to write if the connection is closed.