Syncing with experimental branch.

Attempt to close socket gracefully on error.
Improved behaviour when closing channel.
Renamed example from simple_ to basic_.