Copy sock/in_stream/out_stream before checking for null

Fixes issue #98

If the connection has been closed then these fields may be null.