Automatically close sockets
don't rely on indexes from register/unregister, because they change