Attached socket to user to make nicer logout.

Also added reconnection logic.