Moved attaching to when socket is opened