Catch errors on send

I was getting NetworkErrors when trying to send data to a stream when the underlying data channel had its remote closed. This patch will detect a network error on send and close the connection, and in case another type of error occurs, simply emit an error on the stream without closing.